-->
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.  [ 6 posts ] 
Author Message
 Post subject: Conditions on a Set - can you do this?
PostPosted: Tue Aug 26, 2003 10:23 am 
Newbie

Joined: Tue Aug 26, 2003 9:29 am
Posts: 12
Hey ... a blank forum ;-)

To open my question, first parts of the code:

Code:
<hibernate-mapping>
   <class name="Order" table="ORDERS">
      <id column="ID" name="key" type="long">
         <generator class="sequence"/>
      </id>
      <property column="PRODUCTION_ORDER_NR" length="8" name="productionOrderNr" type="string"/>
      <many-to-one name="orderStatus" class="OrderStatus" column="OSE_ID" outer-join="true"/>
      <set name="orderStatusRealisations" table="ORDER_STATUS_REALISATIONS" sort="natural">
         <key column="OER_ID"/>
         <one-to-many class="OrderStatusRealisation"/>
      </set>
   </class>

   <class name="OrderStatusRealisation" table="ORDER_STATUS_REALISATIONS">
      <id column="ID" name="key" type="long">
         <generator class="sequence"/>
      </id>
      <property column="DATE_REALISED" name="dateRealised" type="timestamp"/>
      <property column="OER_ID" name="orderId" type="long"/>
      <many-to-one name="orderStatus" column="OSE_ID" class="OrderStatus"/>
   </class>

   <class name="OrderStatus" table="ORDER_STATUSES">
      <id column="ID" name="key" type="long">
         <generator class="sequence"/>
      </id>
      <property column="ORDER_STATUS_CODE" length="5" name="orderStatusCode" not-null="true" type="string"/>
      <property column="DESCRIPTION" length="30" name="description" not-null="true" type="string"/>
   </class>
</hibernate-mapping>

public class Order {
   long key;
   String productionOrderNr;
   OrderStatus orderStatus;
   Set orderStatusRealisations;
}

public class OrderStatusRealisation {
   long key;
   Date dateRealised;
   OrderStatus orderStatus;
}

public class OrderStatus {
   long key;
   String orderStatusCode;
   String description;
}


In words:

You have a bunch of Orders, each holding a current State (orderStatus) and a history of old states using a Set of OrderStatusRealisation, each holding a orderState and a timestamp (dateRealised).

Now the problem is, I can't find in the documentation a way of expressing the select where I want to select the orders where the state (orderStatusCode) had a certain value in a defined period.

something like from Order o where o.orderStatusRealisations.orderStatus.orderStatusCode=1000

For some reason this gives me allways a NullPointerException - probably because orderStatusRealisations is a set ...
Is there a working way to express this query???

Thanks


Top
 Profile  
 
 Post subject: Re: Conditions on a Set - can you do this?
PostPosted: Tue Aug 26, 2003 10:30 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Join the association (Hibernate2):

Code:
select state from Order as order join order.orderStatusRealisations as state where state.orderStatusCode = 1000

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 11:05 am 
Newbie

Joined: Tue Aug 26, 2003 9:29 am
Posts: 12
Thanks,

I tried that, but that didn't work ...

There was also a small bug in your code ... it should have been

Code:
select state from Order as order join order.orderStatusRealisations as state where state.orderStatus.orderStatusCode = 1000



The problem is that orderStatusRealisations is a Set (see the mapping file) and invoking 'getOrderStatus' on orderStatusRealisations will be done on the Set instead of the OrderStatusRealisation object.

Is there a way to define the condition on elements of a set???

thanks beforehand


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 11:10 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats why I joined the Set. The 'state' is a single OrderStatusRealisation.

Please check the documentation for "association joining". I've missed the second assocation with "orderStatus" in my example, but your corrected version should work.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2003 11:27 am 
Newbie

Joined: Tue Aug 26, 2003 9:29 am
Posts: 12
OK thanks it works fine now.

btw an alias called 'order' doesn't work because of the 'order by' stuff.

p.s. congrats with the new forum (I always liked the phpBB style)


Top
 Profile  
 
 Post subject: Re: Conditions on a Set - can you do this?
PostPosted: Wed Oct 13, 2010 5:33 am 
Newbie

Joined: Wed Oct 13, 2010 5:25 am
Posts: 10
I spent my whole life trying not to be careless. Women and children can be careless. But not men.

_________________
cheap watches
replica watches uk
replica watches


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

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.