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.
|