[hibernate-issues] [Hibernate-JIRA] Created: (ANN-477) @Formula doesn't work in entities referenced by @JoinColumn(referencedColumnName="...")

Salvatore Insalaco (JIRA) noreply at atlassian.com
Fri Oct 27 06:43:05 EDT 2006


@Formula doesn't work in entities referenced by @JoinColumn(referencedColumnName="...")
---------------------------------------------------------------------------------------

         Key: ANN-477
         URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-477
     Project: Hibernate Annotations
        Type: Bug

    Versions: 3.2.0.ga    
    Reporter: Salvatore Insalaco
 Attachments: ProvaBug.zip

See the attached test (build with ant, place hibernate libraries in lib, run test.Test).
Entity Second has a @Formula property.
Entity First has a many-to-one association with Second, not on the primary key but on the ALT_ID column, using the "referencedColumnName" attribute of the @JoinColumn annotation.

This is NOT the case of an association to a @Formula column (not supported), but a relation on a non-primary column of an entity that happens to have a @Formula property.

During SessionFactory creation an exeption is raised:
java.lang.ClassCastException: org.hibernate.mapping.Formula
  at org.hibernate.cfg.BinderHelper.findPropertiesByColumns(BinderHelper.java:234)
  at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:106)
  at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:63)
  at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
  at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1210)

The bug lies in BinderHelper.findPropertiesByColumns. In the iteration starting at line 233, it tries to find the property that maps the "referencedColumnName", but it doesn't consider that some properties may not have a Column, only a Formula.
The correct version should be something like this:

Iterator columnIt = property.getColumnIterator();
while ( columnIt.hasNext() ) {
  Object next = columnIt.next();
  if (next instanceof Column) {
    Column column = (Column)next;
    if ( columnsToProperty.containsKey( column ) ) {
      columnsToProperty.get( column ).add( property );
    }
  }
}


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