Hi there,
I'm encountering an interesting problem where Hibernate is selecting from a different class to that supplied to the query. I've tried this out on all 3.0.x versions (up to 3.0.5), and with both HQL and Criteria queries.
I have a table called OFFICE. I also have a view called V_USER_OFFICES, which provides a restricted list of office IDs that a particular type of user can see (based on security rules that exists on the database).
The two corresponding objects are mapped as follows:
<hibernate-mapping package="au.com.whatever" schema="CORP">
<class name="Office" table="OFFICE" lazy="true" mutable="false">
<id name="officeID" type="int" column="OFC_NO"/>
<propertyname="name" type="java.lang.String" column="OFC_ENAME" length="40"/>
</class>
<class name="ViewOffices" table="V_USER_OFFICES" lazy="true" mutable="false">
<composite-id>
<key-many-to-one name="office" class="Office">
<column name="OFC_NO" />
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>
I can query for ViewOffices objects fine, and I can also load an Office object fine using Session.get(), but if I try to load Office/s through queries (like the ones below), Hibernate substitues the ViewOffices class into the query instead!
EXAMPLE QUERIES:
from Office o order by o.name
from Office o where o.officeID = 123
Criteria ct = HIBERNATE.createCriteria(Office.class) .add(Restrictions.eq("officeID", new Integer(officeID)));
EXAMPLE EXCEPTIONS: org.hibernate.QueryException could not resolve property: name of: au.com.marsh.client.persistence.ViewOffices [ from au.com.marsh.client.persistence.ViewOffices o order by o.name]
org.hibernate.QueryException) could not resolve property: officeID of: au.com.marsh.client.persistence.ViewOffices [ from au.com.marsh.client.persistence.ViewOffices o where o.officeID = 21]
If I remove the ViewOffices mapping from my configuration, the Office queries work fine. Somehow Hibernate gets confused by the fact that the primary key of of ViewOffices is actually an Office...
Any ideas?
Troy.
|