[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-5729) Only one check constraint is generated when @Min and @Max annotation is used on a single field
Hardy Ferentschik (JIRA)
noreply at atlassian.com
Thu Nov 11 12:47:13 EST 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5729?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Hardy Ferentschik resolved HHH-5729.
------------------------------------
Resolution: Fixed
Applied on master and 3.6 branch
> Only one check constraint is generated when @Min and @Max annotation is used on a single field
> ----------------------------------------------------------------------------------------------
>
> Key: HHH-5729
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5729
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.6.0, 4.0.0.Alpha1
> Environment: Hibernate Core 3.5.5-Final; Hibernate Annotation 3.5.5-Final; Oracle10gDialect
> Reporter: Jens Schauder
> Assignee: Hardy Ferentschik
> Fix For: 3.6.1, 4.0.0.Alpha1
>
> 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: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list