-->
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: one-to-many bidirectional relationship
PostPosted: Sun Nov 13, 2005 5:13 pm 
Newbie

Joined: Sun Nov 13, 2005 5:06 pm
Posts: 3
I have a problem with one-to-many bidirectional relationship. I can see the insert statements being echo'd to the system console but the records are not actually getting inserted into the 'many' table.

I am committing and flushing the session and no exceptions are thrown.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 13, 2005 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If you see the insert statements and its not ending up in the database then you are not using transactions, rolling back the transaction or the database may not have transactions (MySQL in none Innodb mode). If you had provided a simple code snipet then we could possibly suggest further ideas.


Top
 Profile  
 
 Post subject: sample code code from one-to-many bidir problem
PostPosted: Mon Nov 14, 2005 6:29 am 
Newbie

Joined: Sun Nov 13, 2005 5:06 pm
Posts: 3
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();
Employee employee = (Employee)session.load(Employee.class, "1");
Set jobs = employee.getJobs();
if (jobs == null){
jobs = new HashSet();
employee.setJobs(jobs);
}

Job job = new Job();
job.Name = "Work";
jobs.add(job);

session.save(employee);
tx.commit();
session.flush();

snippet from the hibernate file on the Employee end:
<class name="Employee" table="Employee" >
<id name="employeeId" column="employeeId" type="java.lang.String" unsaved-value="undefined">
<generator class="assigned"/>
</id>
<set name="jobs" inverse="true" cascade="all">
<key column="jobId" />
<one-to-many class="Job" />
</set>
</class>

snippet from the hibernate file on the Job end:

<id name="jobId" column="jobId" type="java.lang.Integer">
<generator class="identity"/>
</id>
<many-to-one name="employee"
column="employeeId"
not-null="true" />


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.