maybe i have not expressed my request very clearly.
please allow me to repost my need again.
this is the brief xml of orgUser.
Code:
<hibernate-mapping>
<class name="com.southstandard.me.bean.OrgUser" table="ME_ORG_USER">
<id name="id" column="ID" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">SEQ_ME_ORG_USER</param>
</generator>
</id>
<property name="name" column="NAME" type="string" length="20" not-null="true"/>
<property name="sex" column="SEX" type="string" length="1" not-null="true"/>
<map name="userProp" table="ME_ORG_USER_PROP" lazy="false" cascade="all" sort="unsorted">
<key column="ME_ORG_USER_ID"/>
<index column="PROP_NAME" type="string" length="40"/>
<element column="PROP_VALUE" type="string" length="200" not-null="true"/>
</map>
</class>
</hibernate-mapping>
it mapping this schema in Oracle database:
Code:
ME_ORG_USER
ID Number
NAME Varchar2(20)
SEX Varchar2(1)
Code:
ME_ORG_USER_PROP
ME_ORG_USER_ID Number
PROP_NAME Varchar2(40)
PROP_VALUE Varchar2(200)
in this context, i would like to use orgUser to do something like this:
orgUser.setName("little gates");
orgUser.setSex("f");
orgUser.getUserProp.put("address","moon");
orgUser.getUserProp.put("'age' ","88");
...
the resean i use
PROP to dealwith "address","'age' ", but some style like: orgUser.setAddress("moon"), orgUser.setAge("88") is that
orgUser is my valuable collect data, "name" and "sex" are its necessary fields, but some orgUser has "address" fields while others don't have.
so, i think it is flexible to attach some additional info to orgUser without do any change on database.
such as:
orgUser.getUserProp.put("'contactInfo' ","8373737892");
this is really my original intention.
now here comes some demand i don't know how to achieve with hibernate.
i want these orgUser who's age is like "%8%".
for instance:
id name age
47 tom 78
99 jimmy 8
104 smith 58
all these orgUsers are what i want.
so, i wrote a sql to do this:
Code:
select a.ID from ME_ORG_USER a, ME_ORG_USER_PROP b where a.ID = b.ID and b.PROP_NAME = 'age' and b.PROP_VALUE like '%8%'
it works.
please tell me can i gain my goal by hql?
Code: