I am trying to use merge function, as explained in the following link.
http://www.hibernate-training-guide.com/merge.htmlI wrote the following code.
Code:
Session session = factory.openSession();
Transaction t = session.beginTransaction();
Event event = null;
try {
event = (Event) session.load(Event.class, id);
System.out.println(event.getId());
//event.setName("hai");
t.commit();
}
catch(Exception e)
{
t.rollback();
}
finally {
session.close();
}
Session session2 = factory.openSession();
Transaction t2 = session2.beginTransaction();
Event event2 = null;
try {
event2 = (Event) session2.load(Event.class, id);
System.out.println(event.getId());
//event.setName("hai");
session2.update(event);
t2.commit();
}
catch(Exception e)
{
System.out.println(e);
t2.rollback();
}
finally {
session2.close();
}
I do not get exception when i try to run the above code. But instead i am getting message : reassociated uninitialized proxy.
I was hoping that when i try to execute the following statment session2.saveOrUpdate(event);
I would get UniqueOjbectException.
Please advise.