Home » Eclipse Projects » EclipseLink » Entities OneToMany Composite Primary keys
Entities OneToMany Composite Primary keys [message #1702821] |
Sat, 25 July 2015 08:56 |
Alfredo Marchini Messages: 4 Registered: July 2015 |
Junior Member |
|
|
Hi all,
I have a problem with these entities/tables:
-------------- TABLES --------------
create table parent (id integer auto_increment, dex varchar(30) not null, primary key (id));
create table children (id_parent integer not null, id integer not null, dex varchar(30) not null, primary key (id_parent, id), foreign key (id_parent) references parent(id) on delete cascade);
create table subchildren (id_parent integer not null, id_child integer not null, id integer not null, dex varchar(30) not null, primary key (id_parent, id_child, id), foreign key (id_parent, id_child) references children(id_parent, id) on delete cascade);
-------------- ENTITIES --------------
@Entity
@Table(name = "parent")
public class Parent {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent", orphanRemoval = true)
private List<Child> children;
}
@Entity
@Table(name = "children")
public class Child {
@EmbeddedId
private ChildPk id;
@MapsId
@ManyToOne
@JoinColumn(name = "id_parent")
private Parent parent;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "child", orphanRemoval = true)
private List<SubChild> subchildren;
}
@Embeddable
public class ChildPk {
@Column(name = "id_parent")
private Integer parent;
@Column(name = "id")
private Integer id;
}
@Entity
@Table(name = "subchildren")
public class SubChild {
@EmbeddedId
private SubChildPk id;
@MapsId
@ManyToOne
@JoinColumns({
@JoinColumn(name = "id_parent", referencedColumnName = "id_parent"),
@JoinColumn(name = "id_child", referencedColumnName = "id"),
})
private Child child;
}
@Embeddable
public class SubChildPk {
@EmbeddedId
private ChildPk child;
@Column(name = "id")
private Integer id;
}
The problem is the subchildren table, it persist or merge only the first record in the list.
I searched for a lot but I didn't find anything...
Thank you very much
Bye
|
|
| | | | |
Goto Forum:
Current Time: Thu Dec 26 23:38:00 GMT 2024
Powered by FUDForum. Page generated in 0.03906 seconds
|