A different object with the same identifier value was already associated with the session : [beans.HEmployee#0]

  Databases

Email

Exception in thread “main” org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session : [beans.HEmployee#0] at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:137)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:715)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:707)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:702)
at test.Client.main(Client.java:28)

Spread the Code

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
naik Recent comment authors

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
newest oldest most voted
Notify of
naik
Guest
naik

Session session=getSession();
session.beginTransaction();
Employee e=new Employee(1,"james",25);
session.save(e);
Manager m=new Manager(1,"james",25,"SC","ABC");
session.save(m);
session.beginTransaction();

session.getTransaction().commit();