]
Hardy Ferentschik updated HV-361:
---------------------------------
Fix Version/s: 4.2.0
If you want to vote on an issue do it on this one. Even though the constraint generation
class lives in Core it is really a Validator issue.
Only one check constraint is generated when @Min and @Max annotation
is used on a single field
----------------------------------------------------------------------------------------------
Key: HV-361
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-361
Project: Hibernate Validator
Issue Type: Bug
Affects Versions: 4.1.0.Final
Environment: Hibernate Core 3.5.5-Final; Hibernate Annotation 3.5.5-Final;
Oracle10gDialect
Reporter: Jens Schauder
Assignee: Hardy Ferentschik
Fix For: 4.2.0
Attachments: checkConstraintTest.zip
When generating DDL create scripts fields which have a @Max and @Min annotation only get
check constraints for the @Max constraint.
Example entity class:
{noformat}
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
@Entity
public class TestClass {
@Id
private Long id;
@Max(10)
@Min(2)
private Integer min2Max10;
@Max(99999)
@Min(0)
private Integer min0max99;
}
{noformat}
Code used for generating the DDL script:
{noformat}
public static void main(String[] args) {
AnnotationConfiguration config = new AnnotationConfiguration()
.addAnnotatedClass(TestClass.class);
final String[] script = config
.generateSchemaCreationScript(new Oracle10gDialect());
for (String string : script) {
System.out.println(string);
}
}
{noformat}
Resulting output:
{noformat}
create table TestClass (id number(19,0) not null, min0max99 number(10,0) check
(min0max99>=0), min2Max10 number(10,0) check (min2Max10>=2), primary key (id))
{noformat}
I tried to locate the problem in the hibernate source code. It might be in the
{{applyConstraints}} Method of the {{TypeSafeActivator}} class. It seems that it just
*sets* constraints on a column and doesn't make an attempt to merge a min-constraint
and a max-constraint into one check constraint.
There is also a related Forum thread regarding this issue:
https://forum.hibernate.org/viewtopic.php?f=9&t=1006740
Find the zipped sources for a little test project attached
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: