-1
hql = "select rm.* from remoteunit rm inner join mo m on rm.MOID = m.ID left join
orgmomapping o on rm.MOID = o.MOID join organization org on org.ID = o.ORGANIZATIONID
where m.DOMAINID = :id";
query = session.createSQLQuery(hql);
該查詢返回的對象列表使用當使用休眠
remoteUnitList = (ArrayList<RemoteUnitDetails>)query.list();
查詢時,但得到類轉換異常當我試圖得到一個對象
RemoteUnitDetails details = (RemoteUnitDetails)remoteUnitsList.get(i);
蔭得到類轉換異常。
Iam使用MySQL數據庫。當在hibernate中使用條件時,Iam無法匹配orgmomapping和remoteunit表。因爲
orgmomapping -> id, organizationId, remoteUnitId
remoteunit -> id
此遠程單元ID可能會或可能不會在orgmomapping中。
請sugguest解決
感謝
UPDATE
RemoteUnitDetails.hbm.xml
<hibernate-mapping>
<class name="---.RemoteUnitDetails" table="remoteunit"
lazy="false">
<id name="id" column="ID">
<generator class="increment" />
</id>
<many-to-one name="remoteUnit" column="MOID"
class="---.RemoteUnit" not-null="true"></many-to-one>
<property name="address" column="ADDRESS" />
<property name="postalCode" column="POSTALCODE" />
<property name="city" column="CITY" />
<property name="region" column="REGION" />
<property name="visible" column="VISIBLE" />
<property name="lowPowerMode" column="LOWPOWERMODE" />
<property name="wakeUpInterval" column="WAKEUPINTERVAL" />
<property name="awakeInterval" column="AWAKEINTERVAL" />
<property name="resetAtNextInterval" column="RESETATNEXTINTERVAL" />
<property name="logInterval" column="LOGINTERVAL" />
<property name="sendIntervalLogData" column="SENDINTERVALLOGDATA" />
<property name="sendIntervalAttr1" column="SENDINTERVALATTR1" />
<property name="sendIntervalAttr2" column="SENDINTERVALATTR2" />
</class>
</hibernate-mapping>
RemoteUnit.hbm.xml
<hibernate-mapping>
<class name="---.RemoteUnit" table="mo" lazy="false">
<id name="id" column="ID">
<generator class="increment" />
</id>
<property name="name" />
<property name="aliasName" column="SCREENNAME" />
<property name="description" column="DESCRIPTION" />
<property name="isActive" column="ISLIVE" />
<many-to-one name="domain" column="DOMAINID"
class="---.Domain" not-null="true" />
<!-- Foreign key -->
<many-to-one name="moType" column="MOTYPEID"
class="---.MoType" not-null="true" />
</class>
</hibernate-mapping>
OrgMoMapping.hbm.xml
<hibernate-mapping>
<class name="---.OrgRemoteUnitMapping" table="orgmomapping"
lazy="false">
<id name="id" column="ID">
<generator class="identity" />
</id>
<many-to-one name="organization" column="ORGANIZATIONID"
class="---.Organization" not-null="true"></many-to-one>
<many-to-one name="remoteUnit" column="MOID"
class="---.RemoteUnit" not-null="true"></many-to-one>
</class>
</hibernate-mapping>
如何加入'mo'和'orgmomapping'有其持久性類,我需要兩個明確指定的列沒有地圖,那怎麼辦 –
你可以提供你的bean類,如果可能的話? –
我可以給你hbm映射嗎? –