Embedded Persistence Issue [message #1862631] |
Fri, 15 December 2023 19:15  |
Eclipse User |
|
|
|
I have source code from a legacy project. The source code is using eclipse
JPA tags. I have a parent entity class (obj1) with an Embedded object that contains a
child entity object (obj2) which has One to Many relationship with obj1.
The parent and child objects are created successfully when we persist the parent class.
When we create more child objects in embedded class and do a merge to parent class
only updated statements are created for obj2 and no inserts for new child objects.
Here is a quick description of the classes:
Class Obj1
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "OBJ1_ID")
private int obj1Id;
@Embedded
EmbeddedObj embeddedObj;
}
Class EmbeddedObj
{
@OneToMany(mappedBy = "obj1", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
List<obj2> listObj;
}
Class Obj2
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int obj2Id;
@ManyToOne
@JoinColumn(name = "OBJ1_ID")
private Obj1 obj1;
}
When we switch the implementation to Hibernate from eclipselink all the correct insert
statements are created as expected.
If anyone has any idea why this does not work in Java 7 with eclipselink-2.5.1 I would
be very interested. We have also tried it with Java 8, and 11 with later versions of eclipselink
but it still doesn't work.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03024 seconds