Ok,
I think I found out the problem. If I take the parent out of the composite-id then all works fine. But with the parent as part of the id for the child the query is not built right.
Here is the query with the parent in the key
Code:
<class name="test.obj.Child" table="child">
<composite-id>
<key-many-to-one name="parent" class="test.obj.Parent">
<column name="parent_id" />
</key-many-to-one>
<key-property name="childVal1" column="child_val1"/>
</composite-id>
<property
name="childVal2"
type="java.lang.String"
column="child_val2"
/>
</class>
<class name="test.obj.Parent" table="parent">
<id name="id" type="java.lang.Long" column="parent_id">
<generator class="sequence" >
<param name="sequence">parent_seq</param>
</generator>
</id>
<property name="value1" column="value1"
/>
<property name="value2" column="value2"
/>
<set name="children" lazy="true" inverse="true" cascade="all,delete-orphan">
<key>
<column name="parent_id" />
</key>
<one-to-many class="test.obj.Child" />
</set>
</class>
Code:
Hibernate: select this_.parent_id as parent1_1_0_, this_.child_val1 as child2_1_0_, this_.child_val2 as child3_1_0_ from child this_ where p1_.value1=?
Here is without
Code:
<class name="test.obj.Child" table="child">
<id name="id" type="java.lang.Long" column="child_id">
<generator class="sequence" >
<param name="sequence">child_seq</param>
</generator>
</id>
<property name="childVal1" column="child_val1" />
<property name="childVal2" column="child_val2" />
<many-to-one name="parent" class="test.obj.Parent" not-null="true" >
<column name="parent_id" />
</many-to-one>
</class>
The parent does not change
Code:
Hibernate: select this_.child_id as child1_1_1_, this_.child_val1 as child2_1_1_, this_.child_val2 as child3_1_1_, this_.parent_id as parent4_1_1_, p1_.parent_id as parent1_0_0_, p1_.value1 as value2_0_0_, p1_.value2 as value3_0_0_ from child this_, parent p1_ where this_.parent_id=p1_.parent_id and p1_.value1=?
As you can see as long as parent is not part of the key it builds the join fine.
Here is the trace / debug data
Code:
2006-06-14 06:59:05,189 [main] (AbstractBatcher.java) DEBUG - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-06-14 06:59:05,189 [main] (ConnectionManager.java) DEBUG - opening JDBC connection
2006-06-14 06:59:05,189 [main] (DriverManagerConnectionProvider.java) DEBUG - total checked-out connections: 0
2006-06-14 06:59:05,189 [main] (DriverManagerConnectionProvider.java) DEBUG - using pooled JDBC connection, pool size: 0
2006-06-14 06:59:05,189 [main] (AbstractBatcher.java) DEBUG - select this_.parent_id as parent1_1_0_, this_.child_val1 as child2_1_0_, this_.child_val2 as child3_1_0_ from child this_ where p1_.value1=?
Hibernate: select this_.parent_id as parent1_1_0_, this_.child_val1 as child2_1_0_, this_.child_val2 as child3_1_0_ from child this_ where p1_.value1=?
2006-06-14 06:59:05,189 [main] (AbstractBatcher.java) DEBUG - preparing statement
2006-06-14 06:59:05,229 [main] (NullableType.java) DEBUG - binding 'one' to parameter: 1
2006-06-14 06:59:05,229 [main] (AbstractBatcher.java) DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-06-14 06:59:05,229 [main] (AbstractBatcher.java) DEBUG - closing statement
2006-06-14 06:59:05,239 [main] (JDBCExceptionReporter.java) DEBUG - could not execute query [select this_.parent_id as parent1_1_0_, this_.child_val1 as child2_1_0_, this_.child_val2 as child3_1_0_ from child this_ where p1_.value1=?]
java.sql.SQLException: ORA-00904: "P1_"."VALUE1": invalid identifier