[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-472) @UniqueConstraint declaration is not friendly towards inheritance or reflection

Ted Bergeron (JIRA) noreply at atlassian.com
Mon Oct 23 16:59:04 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-472?page=comments#action_24960 ] 

Ted Bergeron commented on ANN-472:
----------------------------------

I am still puzzled about your suggestion.  Currently I do have the annotations in place, and my hibernate generated DDL has the unique constraints set in Oracle.  If I insert a row that violates the unique constraint I'll get a SQLException.

I'd like to go one better and have my view layer inspect the field of the model bean and on finding a single or composite unique constraint, dynamically generate the DWR code to validate this case.  Thus, a user enters the name field, and tabs to other fields.  DWR fires off an event that tells my app layers to select the one or combination of fields to check if they exist in Oracle.  That returns a boolean to the view which alerts the user to the problem before submit.

I know this is only 99% effective due to the race condition, but the SQLException will cover the other 1%.  

If I try to use the validator for this case, I have to populate a whole bean because getPotentialInvalidValues and getInvalidValues only accept one property otherwise (not multiple for a composite constraint).  Then I'd have to iterate over InvalidValue[] just looking for the specific combination of fields.  This is where I am confused by your suggestion.  Without generating a select, how does the validator check that the unique constraint is not violated?  

> @UniqueConstraint declaration is not friendly towards inheritance or reflection
> -------------------------------------------------------------------------------
>
>          Key: ANN-472
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-472
>      Project: Hibernate Annotations
>         Type: Improvement

>     Versions: 3.2.0.ga
>  Environment: Hibernate 3.2 GA
>     Reporter: Ted Bergeron

>
>
> The current way to define a composite unique constraint is limiting.
> @Table(name="tbl_sky",
>     uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}
> )
> Suppose I have an abstract base class called A that gives me Id and Name, subclassed by abstract class B that gives me Customer.  Then I have many concrete classes that subclass B.  For all of these, I'd want the combination of Name and Customer to be unique.  As I do not use @Table with abstract base classes, I currently have to repeat:  uniqueConstraints = {@UniqueConstraint(columnNames={"name", "customer_id"})}  on all concrete classes.  
> If we had an alternate way to define these constraints at the property level (as XDoclet did with hibernate 2), I could define this in the base classes and inherit the constraint declaration.
> The other need is that I would like to use reflection to scan the properties and apply proper validations in the view layer.  With @Column(unique = true) this is easy to do.  The view layer makes an AJAX call and all is well.  For a composite constraint, it does not work well currently.

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