Hey guys, iam newbie in hibernate
I have an example about many to many relationship and i do it follow this tut
http://viralpatel.net/blogs/hibernate-many-to-many-xml-mapping-example/
But when i run this code, there is an exception "TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.entity.Meeting
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)"
And i must fix my insert code from
Quote:
SessionFactory sf = HibernateUtil.getSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
Meeting meeting1 = new Meeting("Quaterly Sales meeting");
Meeting meeting2 = new Meeting("Weekly Status meeting");
Employee employee1 = new Employee("Sergey", "Brin");
Employee employee2 = new Employee("Larry", "Page");
employee1.getMeetings().add(meeting1);
employee1.getMeetings().add(meeting2);
employee2.getMeetings().add(meeting1);
session.save(employee1);
session.save(employee2);
session.getTransaction().commit();
session.close();
to
Quote:
SessionFactory sf = HibernateUtil.getSessionFactory();
Session session = sf.openSession();
session.beginTransaction();
Meeting meeting1 = new Meeting("Quaterly Sales meeting");
Meeting meeting2 = new Meeting("Weekly Status meeting");
session.save(meeting1);
session.save(meeting2);
Employee employee1 = new Employee("Sergey", "Brin");
Employee employee2 = new Employee("Larry", "Page");
employee1.getMeetings().add(meeting1);
employee1.getMeetings().add(meeting2);
employee2.getMeetings().add(meeting1);
session.save(employee1);
session.save(employee2);
session.getTransaction().commit();
session.close();
and it runs properly
But i thinks this way is not flexible
So, can you tell me know what is the mistake
I'm a newbie in our forum, so iam sorry if i spam(because my english is too bad)
And thanks you very much