-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hibernateNonUniqueException when using current session
PostPosted: Thu Jan 16, 2014 4:14 pm 
Newbie

Joined: Thu Jan 16, 2014 3:46 pm
Posts: 1
I am having a problem when updating a particular entry inside a loop using hibernateSessionFactory.currentSession getting a error i.e hibernateNonUniqueException a different object with the same identifier value is already associated with a session.The following situtaion is depicted below

public Login saveTeacher(TeacherDto teacherObject, List<ExamDto> examsObject, Teacher_DeptDto departmentsObject) throws Exception {
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
Login lg = new Login();

try {
for(Iterator iterator = examsObject.iterator();iterator.hasNext();){

ExamDto exobj=(ExamDto)iterator.next();

String Query = "update ExamDto e set e.id = :teacherId where e.examId = :eId";
Query query = session.createQuery(Query);
query.setParameter("teacherId", teacherObject.getId());
query.setParameter("eId", exobj.getExamId());
session.update(exobj); //***This the area where the problem occurs
}


session.save(teacherObject);

session.save(departmentsObject);
tx.commit();


Please help how this can be rectified ...i n case when I am using openSession() the problem doesn't occur.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.