java - How to use one-to-many and many-to-one annotations correctly? -
good day,
i have started first jpa project based on crm application , have difficulties understanding correct usage of manytoone , onetomany annotations. instance, let's have 2 classes; these account , user classes:
public class account { @onetomany private set<user> userlist = new hashset<user>();
and
public class user { @manytoone private account account;
how correctly annotate many-to-one , one-to-many relationships? i've tried reading docs still not retrieve correct conclusion.
thank attention
a 'canonical' onetomany mapping case, meaning meaning bidirectional, foreign key in table of many-side (the owning side) in case this:
public class account { @onetomany(mappedby="account") private set<user> userlist = new hashset<user>();
and
public class user { @manytoone private account account;
the difference existing code mappedby
attribute, change 2 unidirectional relationships single, bidirectional relationship.
Comments
Post a Comment