A life committed to learning.

Look for the obvious first…

As I like to experiment cool web development frameworks, I decided to make a quick tour on Play! Framework. It was queued 🙂

So, here I was trying the persistence from the framework, that is basically JPA 2.0 with Hibernate as the persistence provider. I was also very interested in knowing what the framework could provide me for data validation, you know, that basic stuff that a framework should give us for free before it can be called wed framework.

I started with a very simple JPA entity like this one:

public class Partner extends Model {

 private String name;

 private BusinessType businessType;

 private Address address;
 //The rest of the code

And the embedded entity Address was defined like this:

public class Address{

	private String addressLineOne;

	private String addressLineTwo;

	private String postalCode;

	private String city;

	private String country;
        //the rest of the code, getters, setters, constructors, etc

The annotations @Required, @MaxSize and @MinSize are used by the validation plugin and is easy to understand what they do.

The @Valid annotation in the address field from Partner entity just tell Play!: “go into that object and validate it according to the annotations you find in the fields.” So everything should validates fine.

At my first unit test to create and retrieve a Partner entity I stuck in a strange behavior that looked like the validation of embedded entities was not working as expected.

Any values I provided in an Address instance always failed against the validation. I was getting validation error messages for all fields in the Address entity:

models.Address.addressLineOne cannot have less than 5 elements
models.Address.addressLineTwo cannot have less than 4 elements
models.Address.postalCode cannot have less than 8 elements
models.Address.city cannot have less than 4 elements
models.Address.country cannot have less than 2 elements

yes, I doubled checked that the strings I provided to the fields were according to validation…

Given that, I found myself  debugging the framework and looking for the problem… debugging is cool 🙂 After three iterations of debug, I could not found why the execution was not going through the code that should validate the minimum size of a field…. WTF

So, I restarted myself and looked at the Address entity again and found :

import net.sf.oval.constraint.MinSize;

where should be:

import play.data.validation.MinSize;

Play! Framework is using OVal in the validation plugin…

Wasn’t that cool?



View more posts from this author

Leave a Reply

Your email address will not be published. Required fields are marked *