-->
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: extra queries being generated
PostPosted: Sun Apr 11, 2004 12:32 pm 
Newbie

Joined: Sun Apr 11, 2004 12:13 pm
Posts: 7
I am a new user to hibernate - using version 2.1.2. I'm sure I'm doing something very basic wrong, but I can't seem to figure it out. I have a very simple one-to-one relationship between 2 tables.

I am using the session.find method to retrieve all of the rows in the table (no where clause). I would expect a single sql statement joining the 2 tables, but instead when I have show-sql set to true, I see that there is one sql statement returning all rows from the first table, and then 1 sql statement being generated for each row in the second table. In this case, thousands of statements are being generated.

Any help is greatly appreciated!!!

The code I am using is:

SessionFactory sessions=createHibernateSessionFactory();
Session session = sessions.openSession();
List joblist = session.find("from Job job");
session.close();


The mappings are defined as follows:

<class name="com.taos.server.hibernate.autosys.Job" table="job">
<cache usage="read-only"/>
<id name="joid" type="int" column="joid" > <generator class="assigned" /> </id>
<property name="jobName" type="java.lang.String" column="job_name" not-null="true" unique="true" length="30" />
<property name="jobType" type="java.lang.String" column="job_type" not-null="true" length="1" />
<one-to-one name="job2" constrained="true" class="com.taos.server.hibernate.autosys.Job2" />
</class>

<class name="com.taos.server.hibernate.autosys.Job2" table="job2">
<cache usage="read-only"/>
<id name="joid" type="int" column="joid" > <generator class="assigned" /> </id>
<property name="timezone" type="java.lang.String" column="timezone" length="50" />
</class>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 11, 2004 8:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Code:
from Job job left join fetch job.job2


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 12, 2004 10:05 am 
Newbie

Joined: Sun Apr 11, 2004 12:13 pm
Posts: 7
Thanks!


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.