I have been surfing for days looking for an answer, I hope you can help.
Hibernate version: 3.1.1
Mapping documents:
Code:
<?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.bcfireinfo.storm.entity.model.log.LogImpl" entity-name="com.bcfireinfo.storm.entity.model.log.Log" table="Log" schema="dbo" catalog="Resource_Tracking" mutable="true">
<cache usage="read-write"/>
<id name="logId" type="long" unsaved-value="null">
<column name="logId" />
<generator class="native" />
</id>
<property name="systemTime" type="long">
<column name="systemTime" not-null="true" />
</property>
<property name="userTime" type="long">
<column name="userTime" not-null="true" />
</property>
<property name="dispatcherUsername" type="string">
<column name="dispatcherUsername" length="50" not-null="true" />
</property>
<many-to-one name="activity" fetch="select" lazy="proxy">
<column name="activityId" />
</many-to-one>
<many-to-one name="resource" fetch="select" lazy="proxy">
<column name="resourceId" />
</many-to-one>
<property name="currentCallSign" type="string">
<column name="currentCallSign" not-null="false"/>
</property>
<property name="state" type="string">
<column name="state" length="50" not-null="false" />
</property>
<property name="comment" type="boolean">
<column name="comment" not-null="true"/>
</property>
<property name="highlighted" type="boolean">
<column name="highlighted" not-null="true"/>
</property>
<property name="message" type="string">
<column name="message" length="1000" not-null="true" />
</property>
<set name="childResources" table="LogResourceMap">
<key column="logId"/>
<many-to-many column="resourceId" class="com.bcfireinfo.storm.entity.model.resource.Resource"/>
</set>
</class>
</hibernate-mapping>
I hace a 2-part problem, the first part is that the many-to-many mapped
childResources are not persisting to the database when I save the logs, but because the rest of the log is persisting correctly, I don't think it will be a difficult issue to solve.
My second problem is that I need to instantiate all the logs (
HibernateTemplate.
find) filtered wher the resource is the one referred to by the resourceid, or it is one of the
childResourcesI can figure out the SQL needed to filter for these records, but I would like to keep my code as free of SQL as possible.
Code:
SELECT Log.logid FROM [dbo].[Log] left join LogResourceMap on log.logid = LogResourceMap.logId left where log.resourceid = ? or LogResourceMap.resourceId = ?
can anyone help with the HQL?
thanks
bhs turf