-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Help newbie in hibernate
PostPosted: Wed May 08, 2013 10:29 pm 
Newbie

Joined: Wed May 08, 2013 10:20 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Help newbie in hibernate
PostPosted: Fri May 10, 2013 3:14 am 
Beginner
Beginner

Joined: Thu May 17, 2007 9:56 am
Posts: 21
Location: India
Hi,

I just gone through the link which you are referring.

There is the typing error in the many-to-many relationship of Meeting.hbm.xml file.

<set name="employees" table="EMPLOYEE_MEETING"
inverse="true" lazy="true" fetch="select">
<key column="EMPLOYEE_ID" />
<many-to-many column="MEETING_ID" class="Meeting" />
</set>

The many to many column should refer the employee table. Can you please correct this and check?

_________________
Kuzhali


Top
 Profile  
 
 Post subject: Re: Help newbie in hibernate
PostPosted: Fri May 10, 2013 3:24 am 
Newbie

Joined: Wed May 08, 2013 10:20 pm
Posts: 2
kuzhali wrote:
Hi,

I just gone through the link which you are referring.

There is the typing error in the many-to-many relationship of Meeting.hbm.xml file.

<set name="employees" table="EMPLOYEE_MEETING"
inverse="true" lazy="true" fetch="select">
<key column="EMPLOYEE_ID" />
<many-to-many column="MEETING_ID" class="Meeting" />
</set>

The many to many column should refer the employee table. Can you please correct this and check?

actually, i use netbeans ide so i generated code properly
i think mistake above is not the my problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.