Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » entitymanager problem merge(merge() problem)
entitymanager problem merge [message #1064551] Wed, 19 June 2013 20:45 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();

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: entitymanager problem merge [message #1065394 is a reply to message #1064551] Tue, 25 June 2013 14:33 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Ensure you set cascade merge in your mapping.


James : Wiki : Book : Blog : Twitter
Previous Topic:How to access Primary Key instance of entity relationship?
Next Topic:OPEN - Disable delete an entity when is its linked in relationships
Goto Forum:
  


Current Time: Thu Apr 25 01:29:25 GMT 2024

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

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

Back to the top