This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Problem in adding/updating and deleting child records......

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
i Have found CustomerInfo Object (with cascade="all" attribute in configuration file),and now trying to update it i do the following

Set a = customerInfo.getCustomerAccounts();
/*customerAccount1 with no primery key (i want to save this record for first time)
*/
a.add(customerAccount1);
/*customerAccount2 with primery key i want this record to be updated in database
*/
a.add(customerAccount2);
/*customerAccount3 with pk i want this record to be deleted
*/
a.remove(customerAccount3);


but when i try to session.saveUpdate(customerInfo) and then session.close(),i get following exception.

net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 474, of class: com.cstel.personalloan.hibernate.CustomerAccount

Can anybody plz tell me where i am doing something wrong.
also there is a case where i want to first delete all those old records in a set and then add new records to it , i am using a.clear() for that is that ok r i should have to do something else for it.
thanks in advance.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know what your exact code looks like, however, please let me take a shot at what may be the cause of your problems.

When you are in-between a transaction and you are adding and updating, etc.. noting is reflected until you do a session.save(aClass) or a session.saveOrUpdate(aClass) and then issue a flush(), changes are not being persisted so you are dealing with phantom objects (records) that do not exist, at least that's my story, and I'm sticking with it (for now).

On your save you should get a primary key back (as long as you are not using session.persist()

youPersistedId = (Integer) session.save(yourClassInstance);

Please accertain that this may be your issue. If I have nudged you in the wrong direction, you have my apolgies.

Tom
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic