Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.0
Iam getting org.hibernate.NonUniqueObjectException
when iam trying to save an object, which is already being updated in same session/transaction.
try {
// Create the instance of Transaction object
session = HibernateUtils.getSession();
trans = session.beginTransaction();
Bean1 aBean1 = new Bean1();
aBean1.setId(1);
aBean1.setDesc("desc1");
session.saveorupdate(aBean1); // update table with desc1 to Id=1
Bean1 aBean2 = new Bean1();
aBean2.setId(2);
aBean2.setDesc("desc2");
session.save(aBean2); // insert new value in the table with id=2.
trans.commit();
session.flush();
session.close();
}
Thanks.