Pierre Sion commented on Bug HHH-7862

Hello, thank you for your reply, sorry if I did not make myself clear in the first place. In the above example, the "@OneToMany" annotation represents the mapping of a Java Map object. The "Hibernate Reference Documentation 3.6.10.Final" indeed states in chapter "7.2.2.2. Maps" that it is the correct way to "map a Map" (so to speak).

From the database point of view, the Map is represented by an association table (named "customer_order" in the above example), which has 3 columns:

  • one column referencing the Map's owner ("customer_id" above)
  • one column holding the Map's key ("somekey" above)
  • one column referencing the Map's value ("order_id" above)

So far so good. My point is, a seemingly improper "unique" database constraint is automatically generated on the "order_id" column of the "customer_order" relation table (when Hibernate is configured to generate the DDL automatically). This prevents different Customers to map the same Order object (not really useful in the real customer-order life, but you see the technical point). May be I interpret wrongly the true meaning of "@OneToMany", which inconditionally imposes distinct Orders, whatever the underlying collection nature (Map in my case). May be I should have used the newer annotation "@CollectionOfElements" instead of "@OneToMany" (unfortunately I do not have my testing environment at disposal for the moment), and in this case the bug is only related to the Hibernate Reference Documentation.

What I notice, though, when the Map value is a "primitive" object (such as a String) instead of an "Order", the "unique" DDL constraint is not generated. The DDL generation behaviour thus does not seem consistent at least.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira