Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Parent{
- private List<Child> _children;
- //...getters and setters
- }
- <class name="Parent">
- ....
- <list name="children" table="link_table">
- <key column="parent_id"/>
- <many-to-many column="child_id"
- class="Children"/>
- </list>
- ...
- </class>
- <class name="Child">
- ...
- <list name="parents" inverse="true" table="link_table">
- <key column="child_id"/>
- <many-to-many column="parent_id"
- class="Parent"/>
- </list>
- ...
- </class>
- @Entity
- public class Employer implements Serializable {
- @ManyToMany(
- targetEntity=org.hibernate.test.metadata.manytomany.Employee.class,
- cascade={CascadeType.PERSIST, CascadeType.MERGE}
- )
- @JoinTable(
- name="EMPLOYER_EMPLOYEE",
- joinColumns=@JoinColumn(name="EMPER_ID"),
- inverseJoinColumns=@JoinColumn(name="EMPEE_ID")
- )
- public Collection getEmployees() {
- return employees;
- }
- }
- @Entity
- public class Employee implements Serializable {
- @ManyToMany(
- cascade = {CascadeType.PERSIST, CascadeType.MERGE},
- mappedBy = "employees",
- targetEntity = Employer.class
- )
- public Collection getEmployers() {
- return employers;
- }
- }
Add Comment
Please, Sign In to add comment