[
http://opensource.atlassian.com/projects/hibernate/browse/HV-361?page=com...
]
Jens Schauder edited comment on HV-361 at 9/2/10 7:18 AM:
----------------------------------------------------------
I think there is a more serious problem then I first thought. We tried a quick fix by
changing the Column.setConstraint:
{noformat}
public void setCheckConstraint(String aCheckConstraint)
{
if (checkConstraint == null || checkConstraint.isEmpty())
checkConstraint = aCheckConstraint;
else if (!checkConstraint.contains(aCheckConstraint))
checkConstraint += " AND " + aCheckConstraint;
}
{noformat}
This fixed the problem in my TestCase. Actually it did so without the {{if
(!checkConstraint.contains(aCheckConstraint))}} part. But when creating the DDL script in
our real project (using a {{SessionFactory}} and setting appropriate properties we got:
- duplicate check Constraints on some columns (we fixed that with the additional
condition.
- no check constraints on other columns
- (thats the scary part: ) which columns had constraint and which not changed on different
executions. This applies for @Min and @Max constraints, as well as for @Length (which
should affect the length of the column, but does so only on some executions).
Not sure if this is still the same bug, or if I am facing two separate issues here.
was (Author: schauder):
I think there is a more serious problem then I first thought. We tried a quick fix by
changing the Column.setConstraint:
{noformat}
public void setCheckConstraint(String aCheckConstraint)
{
if (checkConstraint == null || checkConstraint.isEmpty())
checkConstraint = aCheckConstraint;
else if (!checkConstraint.contains(aCheckConstraint))
checkConstraint += " AND " + aCheckConstraint;
}
{noformat}
This fixed the problem in my TestCase. Actually it did so without the {{if
(!checkConstraint.contains(aCheckConstraint))}} part. But when creating the DDL script in
our real project (using a {{SessionFactory}} and setting appropriate properties we got:
- duplicate check Constraints on some columns (we fixed that with the additional
condition.
- no check constraints on other columns
- (thats the scary part:) which columns had constraint and which not changed on different
executions. This applies for @Min and @Max constraints, as well as for @Length (which
should affect the length of the column, but does so only on some executions.
Not sure if this is still the same bug, or if I am facing two separate issues here.
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira