In a project that I mention a lot there's an persistent model using JPA as an interface to Hibernate.
There was case where I wanted to put extra columns in a @ManyToMany relationship. JPA cannot do that.
So I had to use the Hibernate's @CollectionOfElements.
It works like that: if there are the objects Class and Student, the extra columns go to the wrapper class EnhancedStudent. The EnhancedStudent has a property of type Student.
Now I have a few bugs related to it:
- Causes the @Version of the containing object (Class) to increment on EntityManager.html#find(java.lang.Class, java.lang.Object)
- The creation of an ExtraStudent cannot propagate (cascade) the inner Student - no matter what.
The funniest thing is that the documentation of the @CollectionOfElements is a single line:
Annotation used to mark a collection as a collection of elements or a collection of embedded objects
🙁