1

I have a problem, and I can't fix it. I have two entitys connected with a join table.(many to many).

I insert a row in database. In another session, when I try do add another row it delets before it insert it. For example `example

    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);

now If a create another session another time,

 Meeting meeting2 = new Meeting("new");

    Employee employee1 = new Employee("new", "new");
    employee1.getMeetings().add(meeting2);

It Deletes all the previous data in the join table(EMPLOYEE_MEETING), and in table remains only the last.

There is a thread in forum thread that says I should write equals and hashcode. I generate via eclipse the hashcode() and equals() but its still the same, Hibernate deletes before insterts. Any idea how to stop this ? thank you very much.

Community
  • 1
  • 1
Nick Donovan
  • 37
  • 1
  • 5
  • You will need to post your mappings. – Alan Hay May 12 '14 at 12:49
  • the are in this link [MAPPINGS](http://viralpatel.net/blogs/hibernate-many-to-many-annotation-mapping-tutorial/) – Nick Donovan May 12 '14 at 13:19
  • @NickDonovan you should post them in your question. – V G May 13 '14 at 07:26
  • @NickDonovan whats the value of `hbm2ddl.auto` property in hibernate cfg xml? – Rohit May 14 '14 at 09:11
  • in hibernate cfg.xml I dont have any hbml2ddl.auto... Nevermind guys I resolved it! I did this solution: When I try to reinsert some value, first I do session.get(class that I want,Value of the class). than I can do anything I want , when I do session.save() everything is Ok, it doesnt delete before inserts. – Nick Donovan May 14 '14 at 11:17

0 Answers0