JBoss Enterprise Application Platform 4 and 5
  1. JBoss Enterprise Application Platform 4 and 5
  2. JBPAPP-6475

HHH-6204 - JoinColumn on non key field fails to populate collection

    Details

    • Workaround Description:
      Hide

      Do not use @EmbeddedId.

      Show
      Do not use @EmbeddedId.
    • Release Notes Text:
      Hide
      org.hibernate.PropertyAccessException was thrown if an Entity contained the following conditions:

      1. Uses @EmbeddedId
      2. Uses @JoinTable on a collection or association property/field, which references another property/field of the entity.
      Show
      org.hibernate.PropertyAccessException was thrown if an Entity contained the following conditions: 1. Uses @EmbeddedId 2. Uses @JoinTable on a collection or association property/field, which references another property/field of the entity.
    • Release Notes Docs Status:
      Documented as Resolved Issue
    • Docs QE Status:
      ON_QA
    • Similar Issues:
      Show 9 results 

      Description

      See http://opensource.atlassian.com/projects/hibernate/browse/HHH-6204

      =====
      To duplicate the issue, create three tables in a database with no declared primary or foreign keys. Map entities to two of the tables. One of these entities has a primitive @Id; the other has an @EmbeddedId. Both entities contain an additional field used to join with the third table and populate a collection.

      This works with the entity that has a primitive @Id but for the entity with @EmbeddedId, trying to do anything with the collection after calling the getter results in:

      javax.ejb.EJBException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of jboss.example.DoesNotWorkPk.id1
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
      ....
      Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of jboss.example.DoesNotWorkPk.id1
      at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:58)
      ....
      Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field jboss.example.DoesNotWorkPk.id1 to jboss.example.DoesNotWork
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)

      I've attached a sample project. The relevant files are Works.java, DoesNotWork.java, and DoesNotWorkPk.java
      There's also data.sql to populate a mysql db, but I think any DB will do.
      =====

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            Strong Liu added a comment -

            org.hibernate.PropertyAccessException may be thrown if an Entity:
            1. using @EmbeddedId
            2. @JoinTable on a collection or association property/field which reference to another property/field of the entity
            for example:

            @EmbeddedId
            private MyPk id;
            private Long name;
            @CollectionOfElements
            @JoinTable(
            name="GLOBAL_NOTES",
            joinColumns=@JoinColumn(name="text_id", referencedColumnName="name"))
            private Set<String> globalNotes = new HashSet<String>();

            there is no workaround yet unless not using @EmbeddedId

            Show
            Strong Liu added a comment - org.hibernate.PropertyAccessException may be thrown if an Entity: 1. using @EmbeddedId 2. @JoinTable on a collection or association property/field which reference to another property/field of the entity for example: @EmbeddedId private MyPk id; private Long name; @CollectionOfElements @JoinTable( name="GLOBAL_NOTES", joinColumns=@JoinColumn(name="text_id", referencedColumnName="name")) private Set<String> globalNotes = new HashSet<String>(); there is no workaround yet unless not using @EmbeddedId
            Hide
            Piotr Nowicki added a comment -

            I also bumped into this PropertyAccessException when using @MapsId and @EmbeddedId. I've published an example at StackOverflow: http://stackoverflow.com/questions/7984356/hibernate-exception-with-mapsid-embeddedid

            I don't really get it... Is the only workaround really 'not to use @EmbeddedId?' Is it a correct behaviour from the JPA 2.0 specification point of view?

            Show
            Piotr Nowicki added a comment - I also bumped into this PropertyAccessException when using @MapsId and @EmbeddedId. I've published an example at StackOverflow: http://stackoverflow.com/questions/7984356/hibernate-exception-with-mapsid-embeddedid I don't really get it... Is the only workaround really 'not to use @EmbeddedId?' Is it a correct behaviour from the JPA 2.0 specification point of view?
            Hide
            Alessandro Lazarotti added a comment - - edited

            Another workaround is using at HQL directly the id fields instead of id instance.
            For example:

            ...
            where someEntity.id.firstValue = :firstValue and someEntity.id.secondValue = :secondValue

            instead of
            ...
            where someEntity.id = :entityPk

            Show
            Alessandro Lazarotti added a comment - - edited Another workaround is using at HQL directly the id fields instead of id instance. For example: ... where someEntity.id.firstValue = :firstValue and someEntity.id.secondValue = :secondValue instead of ... where someEntity.id = :entityPk
            Hide
            Brett Meyer added a comment -

            Appears to have been corrected under JBPAPP-6476's commits

            Show
            Brett Meyer added a comment - Appears to have been corrected under JBPAPP-6476's commits
            Hide
            Martin Simka added a comment -

            verified on EAP 5.3.0.ER3, although it seems like it was fixed in 5.2.0 already. Last EAP version where the issue is being present is 5.1.2.

            Show
            Martin Simka added a comment - verified on EAP 5.3.0.ER3, although it seems like it was fixed in 5.2.0 already. Last EAP version where the issue is being present is 5.1.2.

              People

              • Assignee:
                Brett Meyer
                Reporter:
                Chris Sams
              • Votes:
                3 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development