wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Session.evict() and update() doesn't works. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Session.evict() and update() doesn Watch "Session.evict() and update() doesn New topic
Author

Session.evict() and update() doesn't works.

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
I am updating a record with the following code :
The table which gets updated has composite primary key (class,section,rollno,year)

But this code throws an exception relating to primary key violation.
I wonder how pk is violated, since the rollno is changed, and this rollno is not allotted to anyone.

Strange thing is that this code works with same values



In this code i have deleted the old record and then, save the new one (wrong way of updating)


kunal
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Have you tried the call to update() method without the call to evict?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks for your reply James Boswell.
No , i haven't tried that.

But before trying that i wonder why the code posted by me doesn't works
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
The problem i am facing is that the delete() deletes all the records with that specified roll no regardless of year.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

How have you defined your composite key on the entity? It sounds like it isn't working correctly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session.evict() and update() doesn't works.