[hibernate-issues] [Hibernate-JIRA] Commented: (HV-361) Only one check constraint is generated when @Min and @Max annotation is used on a single field

Alexander Kunkel (JIRA) noreply at atlassian.com
Fri Sep 3 05:06:18 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HV-361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38278#action_38278 ] 

Alexander Kunkel commented on HV-361:
-------------------------------------

Do there exists a Hibernate-Core issue i can vote? DDL generator with TypeSafeActivator is inside of hibernate3.jar not the validation jar.

> 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
>         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