Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1
Mapping documents:
ASSUMED:
ship.hbm.xml
Code:
<hibernate-mapping>
<class name="my.maritime.model.Ship"
table="Ship">
<id name="ShipId" type="java.lang.Long">
<column name="SHIPID" precision="22" scale="0" />
<generator class="native">
<param name="sequence">SEQ_SHIP_ID</param>
</generator>
...
<set name="containers"
lazy="false"
inverse="true">
<key column="SHIPID"/>
<one-to-many class="my.maritime.model.Container"/>
</set>
</class>
</hibernate-mapping>
container.hbm.xmlCode:
<hibernate-mapping>
<class name="my.maritime.model.Container"
table="CONTAINER">
<id name="containerId" type="java.lang.Long">
<column name="CONTAINERID" precision="22" scale="0" />
<generator class="native">
<param name="sequence">SEQ_CONTAINER_ID</param>
</generator>
</id>
...
<set name="boxes"
lazy="false"
inverse="true">
<key column="CONTAINERID"/>
<one-to-many class="my.maritime.model.Box"/>
</set>
<many-to-one
name="ship"
lazy="false"
column="SHIPID"
class="my.maritime.model.Box"
not-null="false"/>
</class>
</hibernate-mapping>
box.hbm.xmlCode:
<hibernate-mapping>
<class name="my.maritime.model.Box"
table="box">
<id name="documentId" type="java.lang.Long">
<column name="BOXID" precision="22" scale="0" />
<generator class="native">
<param name="sequence">SEQ_BOX_ID</param>
</generator>
</id>
<property name="weight" type="java.lang.Long">
<column name="weight" length="20" />
</property>
...
<many-to-one
name="container"
lazy="false"
column="CONTAINERID"
class="my.maritime.model.Container"
not-null="true"/>
</class>
</hibernate-mapping>
Name and version of the database you are using:
ORACLE 9 and 10
OK, a ship stores 0-n containers.
A container belongs to 0-1 ship.
Container stores 0-n boxes.
A Box belongs to 0-1 container.
I have enourmous difficulties selecting ships depending on their SUM(weight) of boxes.
OK there is a HQL solution(allthoug I even fight on this front, either i just get the ship IDs but no objects or it results in a "ORA-00979: not a GROUP BY expression" error.)
I would very much prefer a solution with pure Hibernate API classes. Is there a solution using Criteria??? Any hints please.