Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » merge problem(merge problem)
merge problem [message #1064554] Wed, 19 June 2013 21:02 Go to next message
kamal na is currently offline kamal naFriend
Messages: 3
Registered: June 2013
Junior Member
I have a problem with the entitymanager
times and need your help.
I just want to save time and merge two tables each time
the tables have 1to n relationship
my trouble at the entitymsnsger.merge (table1). tabellle1 which is updated. table2 but does not update

many thanks for your help

public void save(Object1 object1, List<Object2> object2List) {
// TODO Auto-generated method stub
try {

Tabelle1 tabelle1 = new Tabelle1();


List<Tabelle2> tabelle2List= new ArrayList<Tabelle2>();
if (object2List!= null) {
for (Object2 Object2new : object2List) {

Tabelle2 tabelle2 = new Object2new ();


tabelle2.add(tabelle2new );


// add list von tabelle2 to tabelle1

try {
// Update tabelle1

Tabelle1 tabelle1new= entityManager.find(Tabelle1 .class, tabelle1.getNummer());
if (tabelle1new== null) {
// transaction type=JTA : container managed transaction
entityManager.persist(Tabelle1 );

} else {

entityManager.merge(Tabelle1 );

} catch (Exception e) {



} catch (ClassCastException e) {
System.out.println("Class Cast Exception");
} catch (IllegalArgumentException e) {
System.out.println("Illegal Argument Exception");
} catch (Exception e) {
System.out.println("Generic Exception");
Re: merge problem [message #1064747 is a reply to message #1064554] Thu, 20 June 2013 19:01 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1300
Registered: July 2009
Senior Member
Does your Tabelle1 bewerbers relationship have the cascade merge and cascade persist settings? Otherwise the merge and persist operations stop at the passed in Tabelle1 instance. Also note that in your code, there is no need to call persist - merge will check if the entity exists and insert it if it doesn't. Persist on the other hand will force inserts, so while you know you want to insert the Tabelle1, it will also cascade to the referenced Tabelle2 instances and force them to be inserted as well. Merge would allow for the provider to check their existence and decide what to do.

Best Regards,
Previous Topic:BeanValidation at preUpdate for unchanged entities?
Next Topic:Unknown column hashcode, value, count, offset
Goto Forum:

Current Time: Wed Jun 20 11:56:44 GMT 2018

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

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

Back to the top