-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need outer join to be used but Hibernate using inner join
PostPosted: Tue May 10, 2005 6:43 pm 
Newbie

Joined: Tue May 10, 2005 2:22 pm
Posts: 10
Hibernate version: 3.0.3

Mapping documents:
<class name="PersonBase" table="PERSONS">
<id name="id" column="pauth_id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="HPTCode" column="hpt_code"/>
<one-to-one name="personName" class="PersonName" property-ref="personKey"/>
<set name="orgNames" outer-join="true">
<key><column name="pauth_pauth_id"/></key>
<one-to-many class="OrgName"/>
</set>

Name and version of the database you are using: SQL Server 2000

The generated SQL (show_sql=true):
select ... from CUSTOMERS this_ inner join PERSON_NAMES person1_ on this_.pauth_id=person1_.pauth_pauth_id inner join ORG_NAMES org2_ on this_.pauth_id=org2_.pauth_pauth_id inner join ADDRESSES address3_ on this_.pauth_id=address3_.pauth_pauth_id where ((person1_.active_flag=? and person1_.effective_end_date>=? and person1_.prsn_first_given_name_txt like ? and person1_.prsn_surname_txt like ?) or (org2_.active_flag=? and org2_.effective_end_date>=? and org2_.orgnztn_name_txt like ?)) and address3_.active_flag=?

Hibernate debug log:

16:19:09,453 DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
16:19:09,484 DEBUG org.hibernate.type.StringType - binding 'Y' to parameter: 1
16:19:09,484 DEBUG org.hibernate.type.TimestampType - binding '2005-05-10 16:19:09' to parameter: 2
16:19:09,484 DEBUG org.hibernate.type.StringType - binding 'D%' to parameter: 3
16:19:09,484 DEBUG org.hibernate.type.StringType - binding 'SMITH%' to parameter: 4
16:19:09,484 DEBUG org.hibernate.type.StringType - binding 'Y' to parameter: 5
16:19:09,484 DEBUG org.hibernate.type.TimestampType - binding '2005-05-10 16:19:09' to parameter: 6
16:19:09,484 DEBUG org.hibernate.type.StringType - binding 'SMITH%' to parameter: 7
16:19:09,484 DEBUG org.hibernate.type.StringType - binding 'Y' to parameter: 8
16:19:09,594 DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
16:19:09,594 DEBUG org.hibernate.loader.Loader - processing result set
16:19:09,594 DEBUG org.hibernate.loader.Loader - done processing result set (0 rows)
16:19:09,594 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
16:19:09,594 DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:19:09,594 DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
16:19:09,609 DEBUG org.hibernate.loader.Loader - total objects hydrated: 0

Problem description:

I need to select some data from several tables. One table contains personal names and another table contains organization names. I have added Criteria to generate a WHERE on some columns in these two tables but I want Hibernate to do an outer join on the org name table because a name may not exist in that table. However, Hiberate is generating sql that only does an inner join. An abbreviated form of the sql is given above.

No results are being returned because it's doing an inner instead of an outer join on ORG_NAMES.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 6:49 pm 
Newbie

Joined: Tue May 10, 2005 2:22 pm
Posts: 10
oops, CUSTOMERS should be PERSONS in the generated SQL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.