Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » merge problem(merge problem)
merge problem [message #1064554] Wed, 19 June 2013 17:02 Go to next message
Eclipse UserFriend
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();

tabelle1.setNummer(object1.getNnummer());
tabelle1.setName(object1.getName());
tabelle1.setLokal(object1.getLokal());


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

Tabelle2 tabelle2 = new Object2new ();

tabelle2.setNummer(jobCondidate.getNummer());
tabelle2.setName(jobCondidate.getName());
tabelle2.setNickname(jobCondidate.getNickname());


tabelle2.add(tabelle2new );

}
}

// add list von tabelle2 to tabelle1
tabelle1.setBewerbers(tabelle2);

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) {

e.getMessage();

}

} catch (ClassCastException e) {
System.out.println("Class Cast Exception");
e.printStackTrace();
} catch (IllegalArgumentException e) {
System.out.println("Illegal Argument Exception");
e.printStackTrace();
} catch (Exception e) {
System.out.println("Generic Exception");
e.printStackTrace();
}
}
Re: merge problem [message #1064747 is a reply to message #1064554] Thu, 20 June 2013 15:01 Go to previous message
Eclipse UserFriend
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,
Chris
Previous Topic:BeanValidation at preUpdate for unchanged entities?
Next Topic:Unknown column hashcode, value, count, offset
Goto Forum:
  


Current Time: Sun Jul 06 05:32:12 EDT 2025

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

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

Back to the top