josemoreira wrote:
HEllo, im using JPA (EJB3) for a website where i need to map the relationship between users.
I have the old User class:
[..]
a UserRelationship class:
Hi!
I also have basically the same problem with JPA and Hibernate.
I've got a class to store architectural information.
The architecture class has an id, title, description, styleType and additional data that is optional and only added to a additional table if required (formal architecture description).
The architecture styleType can be "general-purpose", "abstract" and "concrete", so I use the Java Enum and "@Enumerated(EnumType.STRING)" as JPA Annotation.
The different architectures are then referencing each other, but it's not a simple "an archicitecture has only one parent". One concreate architecture can be linked as "loose extension" to one general-purpose object and the same concrete architecture can be an "strictly inherited" from another general-purpose object.
It's an m:n referencing object.
Without JPA/Hibernate I would just create two tables, one for the architecture objects and another table for the relationship information.
As a general-purpose style object has no "parent" there will be no entry in the ArchitectureRef table. A style can also not reference itself but that are things that I take care of in my application.
Architectures table columns:
id, title, description and styleType (which is an Enum that can be: "general-purpose", "abstract" and "concrete")
ArchitectureRef table columns:
architectureId, architectureParentId and typeOfReference
TypeOfReference is again an Enum that can be: "strict", "variant", "loose", "builds-upon".
The big question is how to define this in a Java POJO with JPA-Annotations using Hibernate?
Can this be done using "set", "collection",..? If yes, how?
All books and other resources I searched so far do not cover the problem with these referenced objects with more then one parent.
As my problem described above is basically the same problem that josemoreira described I hope someone shows us an example class to do this.
Many thanks in advance.
[Edit1] Fixed some typos