We had a sql-query which was previously running until I added a many-to-one property to the class the query returns. It seems that query tries to find a column for the joined object (ent.changeReason) instead of using the return-join object. I think this is the case as if I uncomment the commented line at the bottom of the query {ent.changeReason} corresponds to 'ChangeR18_1_0_'
I don't really understand how this differs from the example in the documentation apart from the composite key and join type.
http://www.hibernate.org/hib_docs/v3/re ... eries.html
I have tested the mappings (ChangeReason and EntityAuditLog) individually and can read from them using session.load and sess.createQuery.
Thanks,
Wayne.
Hibernate Version: 3.2.1.ga
DB: MSSQL2000
Mapping:
Code:
<class name="EntityAuditLog" table="AuditLogRecord" mutable="false">
<composite-id class="EntityAuditID" name="RecordId">
<key-property name="name" column="EntityName" type="string"/>
<key-property name="type" column="EntityType" type="string"/>
<key-property name="action" column="Action" type="AuditAction"/>
<key-property name="principal" column="UpdatedBy" type="string"/>
<key-property name="date" column="UpdatedDate" type="EIDate"/>
</composite-id>
<property name="EntityId" column="EntityId" type="string" not-null="true"/>
<property name="EntityId1" column="EntityId1" not-null="false"/>
<property name="EntityId2" column="EntityId2" not-null="false"/>
<property name="EntityId3" column="EntityId3" not-null="false"/>
<set name="propertyAudits" cascade="all-delete-orphan">
<key>
<column name="EntityName"/>
<column name="EntityType"/>
<column name="Action"/>
<column name="UpdatedBy"/>
<column name="UpdatedDate"/>
</key>
<one-to-many class="PropertyAuditLog"/>
</set>
<many-to-one name="changeReason" column="ChangeReasonID" not-null="false" class="ChangeReason"/>
</class>
Query: Code:
<sql-query name="TestAuditLogQuery" callable="false" cacheable="false" flush-mode="never">
<return alias="ent" class="EntityAuditLog"/>
<return-join alias="cr" property="ent.changeReason"/>
select
prop.EntityName as {ent.id.name},
prop.EntityType as {ent.id.type},
prop.Action as {ent.id.action},
prop.UpdatedBy as {ent.id.principal},
prop.UpdatedDate as {ent.id.date},
prop.EntityId as {ent.EntityId},
prop.EntityId1 as {ent.EntityId1},
prop.EntityId2 as {ent.EntityId2},
prop.EntityId3 as {ent.EntityId3},
cr.ChangeReasonID as {cr.id},
cr.ChangeReason as {cr.ChangeReason}
<!-- ,cr.blah as {ent.changeReason} -->
from AuditLogRecord prop
left join AuditLogChangeReason cr on prop.ChangeReasonID = cr.ChangeReasonID
</sql-query>
Resulting Query:Code:
select
prop.EntityName as EntityName1_0_,
prop.EntityType as EntityType1_0_,
prop.Action as Action1_0_,
prop.UpdatedBy as UpdatedBy1_0_,
prop.UpdatedDate as Updated10_1_0_,
prop.EntityId as EntityId1_0_,
prop.EntityId1 as EntityId3_1_0_,
prop.EntityId2 as EntityId4_1_0_,
prop.EntityId3 as EntityId5_1_0_,
cr.ChangeReasonID as ChangeRe1_0_1_,
cr.ChangeReason as ChangeRe2_0_1_
from AuditLogRecord prop
left join AuditLogChangeReason cr on prop.ChangeReasonID = cr.ChangeReasonID
Stacktrace: Code:
WARN [JDBCExceptionReporter] JDBCExceptionReporter.java:77 - SQL Error: 0, SQLState: S0022
ERROR [JDBCExceptionReporter] JDBCExceptionReporter.java:78 - [TDS Driver]Column 'ChangeR18_1_0_' not found.
ERROR [SQLServerDialect] SQLServerDialect.java:129 - Failed to parse SQL State: S0022