Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Embedded Persistence Issue(Embedded objects that contains a child which has one to many relationship not persisting during merge of parent.)
Embedded Persistence Issue [message #1862631] Fri, 15 December 2023 19:15 Go to next message
Mike Connolly is currently offline Mike ConnollyFriend
Messages: 1
Registered: December 2023
Junior Member
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.
Re: Embedded Persistence Issue [message #1862754 is a reply to message #1862631] Wed, 27 December 2023 16:21 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 54
Registered: December 2021
Member
Could be a bug - how are you updating the listObj, and what exactly do you mean by 'merge to parent class'? Does it work if you make other changes to the EmbeddedObj class, or try a different change tracking option (possibly deferred - https://eclipse.dev/eclipselink/documentation/2.4/jpa/extensions/a_changetracking.htm#:~:text=Using%20%40ChangeTracking%20may%20improve%20commit,will%20not%20detect%20the%20change )

Best Regards,
Chris
Previous Topic:JDBC bind parameters only for one of them
Next Topic:delete operation not happening in child object for relationship mapping
Goto Forum:
  


Current Time: Sat Apr 27 21:19:31 GMT 2024

Powered by FUDForum. Page generated in 0.03131 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top