I have 2 tables, View(viewId INTEGER) and Auth(login VARCHAR). I want to Create another table from joining View and Aut as follow using hibernate 4 and annotations. Note I am adding another field visibile in that table.
@Entity
public class ViewAut {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="VIEW_VIEWID")
private Rview view;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="AUT_USERID")
private Aut aut;
@Column
private boolean visibile;
// Getter & setters
}
View object has a Set of ViewAut objects
@Entity
public class View {
// DONT KNOW HOW TO WRITE ANNOTATION FOR THIS SCENARIO
private Set<ViewAut> authorizations;
Similary, Auth object has a Set of ViewAut objects
@Entity
public class Aut {
// DONT KNOW HOW TO WRITE ANNOTATION FOR THIS SCENARIO
private Set<ViewAut> authorizations;
Can you please guide me on how to write those join in hibernate 4 annotations?
What you are trying to accomplish can't be done with Embeddable
. JPA defines Embeddable
a class whose instances are stored as an intrinsic part of an owning entity and share the identity of the entity. Each of the persistent properties or fields of the embedded object is mapped to the database table for the entity, see Embeddable
In this case you should model this ViewAut
as another Entity
, and using OneToMany
to establish the relationship between them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.