-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: double JOIN / GROUP BY / AGREGATE Function ...
PostPosted: Tue Jan 23, 2007 11:41 am 
Beginner
Beginner

Joined: Thu Nov 23, 2006 5:09 am
Posts: 21
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.xml

Code:
<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.xml


Code:
<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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.