Hi everybody, i’m trying to implement this database structure using jpa and hibernate (this is an example of the real structure).
I’m not able to connect Child entity with Parent by those 3 keys, where i’m wrong? if i remove primaryKey (pid) it works, but i need to connect all of them.
thank to all!
@Entity
public class GrandParent implements Serializable {
/** */
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer gid;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "grandparent")
private Set<Parent> parents;
//..getters and setters
}
@Entity
public class Parent implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer pid;
@ManyToOne(fetch=FetchType.Lazy)
@JoinColumn(name = "gid", referencedColumnName = "gid")
private GrandParent grandparent;
@Column(name = "fk2")
private String fk2;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
private Set<Child> childs;
//getters and setters
}
@Entity
public class Child implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
@ManyToOne(fetch=FetchType.Lazy)
@JoinColumn(name = "pid", referencedColumnName = "pid")
@JoinColumn(name = "gid", referencedColumnName = "gid")
@JoinColumn(name = "fk2", referencedColumnName = "fk2")
private Parent parent;
//getters and setters
}