休眠。 SQL查询。 XML映射

时间:2016-02-02 11:06:41

标签: xml hibernate mapping hibernate-mapping

有映射xml:

.switchery {
    color: #c00;
    secondaryColor: #b7b7b7;
    jackColor: #fff;
    jackSecondaryColor: #f3f3f3;
}

<?xml version="1.0" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.example.MyObject" table="OWNER" where="service = 462"> <id name="id" column="id" unsaved-value="null"/> <property name="name" column="name" insert="false" update="false"/> <property name="description" column="description" insert="false" update="false"/> </class> </hibernate-mapping> 还必须包含一组类MyObject的对象:

HerObject

但我需要使用复杂的sql-query来获取<set name="herObjects" lazy="false"> <key /> <one-to-many class="com.example.HerObject"/> </set> 。为此,指出设计(在简化的sql示例中):

herObjects

应该从当前<sql-query name="herObjSQLQuery"> <load-collection alias="ho" role="com.example.MyObject.herObjects"/> <![CDATA[ select {ho.*} from her_obj ho where owner_id = :id ]]> </sql-query> {而非: id而不是id。单位MyObject也添加了一行:

set

结果是以下xml:

<loader query-ref="com.example.MyObject.herObjSQLQuery" />

哪里出错?如何在sql-query中替换<?xml version="1.0" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.example.MyObject" table="AAA" where="service = 462 and status = 1 and conference_number > 0"> <id name="id" column="id" unsaved-value="null"/> <property name="name" column="name" insert="false" update="false"/> <property name="description" column="description" insert="false" update="false"/> <set name="herObjects" lazy="false"> <key /> <one-to-many class="com.example.HerObject"/> <loader query-ref="com.example.MyObject.herObjSQLQuery" /> </set> <sql-query name="herObjSQLQuery"> <load-collection alias="ho" role="com.example.MyObject.herObjects"/> <![CDATA[ select {ho.*} from her_obj ho where owner_id = :id ]]> </sql-query> </class> </hibernate-mapping> 的当前id值?

0 个答案:

没有答案