Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2x
This is a question about using native SQL queries. Has anyone encountered this?
I have a user class with a component for address class. The address data however is in the user table.
<hibernate-mapping>
<class name="User"
table="USER" >
<id name="UserId" column="FRANCHISE_ID">
<generator class="increment"></generator>
</id>
<property name="firstname" column="USER_FIRST NAME" />
<property name="lastname" column="USER_LAST_NAME" />
<component name="address"
class="com.edmunds.localsearch.model.Address">
<property name="street" type="string" column="STREET"></property>
<property name="city" type="string" column="CITY"></property>
</component>
</class>
<sql-query name="findUser">
<return alias="user" class="User"/>
<![CDATA[ SELECT
user.USER_FIRST NAME as {user.firstname},
user.USER_LAST_NAME as {user.lastname} ,
user.STREET as {user.street} ,
user.CITY as {user.city}
FROM USER user ]]>
</sql-query>
</hibernate-mapping>
For a very specific reason i need to use a native SQL query here.
Is there a way to retrieve the component properties from this SQL query.
Obviously {user.street} is incorrect here. I've also tried {user.address.street}, {address.street} etc.
I've tried all possible combinations but it seems you can retrieve only the direct properties using SQL.
I cannot have a mapping for address as there is no id or association here.
Any ideas?
Thanx in advance