Hi,
I am migrating a project from Hibernate 3.3.2 with Hibernate Validator 3.1.0 to Hibernate 3.5.5 with Hibernate Validator 4.1.0. It seems that the new implementation of the @Range constraint has some flaws:
- The resulting schema check constraint contains only the "min" or the "max" condition, but never both (see below property "anzahlAchsen" / column "anzahl_achsen")
- The default value of Range.min is 0 (in 3.1.0 it was Long.MIN_VALUE). Thus, when defining a constraint for positive numbers, the minimum value is ignored (see below property "laengeUeberPuffer" / column "laenge_ueber_puffer")
Example Bean Class:Code:
@Entity
public class Lok extends AbstractDbObject
{
...
@NotNull
@Range(min = 2, max = 10)
private Integer anzahlAchsen;
@NotNull
@Range(min = 0, max = 99999)
private Integer laengeUeberPuffer;
...
}
Schema created by Hibernate 3.3.2/Validator 3.1.0:Code:
create table lok (
...
anzahl_achsen number(10,0) not null check (anzahl_achsen>=2 and anzahl_achsen<=10),
...
laenge_ueber_puffer number(10,0) not null check (laenge_ueber_puffer>=0 and laenge_ueber_puffer<=99999),
...
);
Schema created by Hibernate 3.5.5/Validator 4.1.0:Code:
create table lok (
...
anzahl_achsen number(10,0) not null check (anzahl_achsen>=2),
...
laenge_ueber_puffer number(10,0) not null,
...
);
Regards,
Wolfgang
P.S. What happened to the PropertyConstraint interface? It was such a nice and easy way to implement database schema constraints based on bean validation! Why did you drop it?