Hibernate version: 2.18
Mapping documents:
Code:
<class name="com.example..User" table="user_core" >
<id name="id" type="java.lang.Long" unsaved-value="null">
<generator class="native"/>
</id>
<property name="name" type="string" unique="true" />
<property name="password" type="string"/>
<map name="textData" lazy="false" cascade="all-delete-orphan">
<key column="userid"/>
<index column="property" type="string"/>
<element column="data" type="string"/>
</map>
</class>
Code:
table user_core
--------------------------
id | name | password
--------------------------
1 | bob | builder
2 | bill | 1234
table textData
------------------------------------
userid | property | data
------------------------------------
1 | 'phonenumber' | '012-3456789'
1 | 'faxnumber' | '012-3456789'
2 | 'phonenumber' | '014-5678901'
I would like to know how to query (in HQL) the user with phonenumber 012-3456789
I would do something like this:
select this from com.example.User this
join this.textData textData
where textData.key = 'phoneNumber' and textData.value = '012-3456789'
But that doesn't work. I can't user 'key' and 'value' as properties of the Map object. Nor can i use 'index' or 'element'. The only option is to use indices and elements, but i don't want to match multiple elements, I want to match a single key value pair. Is this possible in HQL or am I restricted to native SQL?