Could you please help me with such case?
I have simple <Entity1>
@Entity @Table(name="ENTITY1") public class Entity1 { @Id @GeneratedValue private Long id; @Column(name="name") private String name; }
and I need without changing it (because <Entity1> is in another library) introduce many-to-many relation between the <Entity1> and <Item>.
Will it be enough just do like this:
@Entity public class Entity2 extends Entity1 {
Set<Element> elements;
@ManyToMany(targetEntity = Element.class, fetch = FetchType.LAZY) @JoinTable( name = "entity1_element", joinColumns = {@JoinColumn(name = "ent_id")}, inverseJoinColumns = {@JoinColumn(name = "elm_id")} ) public Set<Element> getElement() { return this.elements; } ...
}
Or there is a better way to do it?
Thank you
|