Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the call to update() method without the call to evict?
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem i am facing is that the delete() deletes all the records with that specified roll no regardless of year.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you defined your composite key on the entity? It sounds like it isn't working correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic