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: complex query string : howto ?
PostPosted: Thu Oct 08, 2009 5:25 am 
Newbie

Joined: Thu Oct 08, 2009 5:02 am
Posts: 2
Hi all,
I'm a newbie to HQL \ EJBQL, and I hoping to get some help with the right way of composing a query string:

(It's a Seam project)
a Sale has a List of Items:

Code:
@Entity
@Name("sale")
public class Sale extends MyEntity {
     private List<Item> items = new ArrayList<Item>();

     ...

     @OneToMany(cascade =
                        {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE},
         mappedBy="sale")
     @org.hibernate.annotations.Cascade(value=
                        {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
     public List<Item> getItems() {
      return items;
     }
     
     ...
}


An Item is nothing more than a bridge between a Sale and a Product - it references one of each and specifies the amount purchased:

Code:
@Entity
@Name("item")
public class Item extends MyEntity implements MyProxy<Item> {

   Product product;
   Sale sale;   
   Integer amount;

        @NotNull
   public Product getProduct() {
      return product;
   }

   @NotNull
   @ManyToOne
   public Sale getSale() {
      return sale;
   }

        ...
}


And a Product, by the way, has no awareness of either Sales or Items:

Code:
@Entity
@Name("product")
public class Product extends MyEntity {

   private String name;
   private String model;

        ....
}


SO: Given some product X, What would be the query string to

Code:
Get all Sales that have an Item in them whose Product is X

??


Also if anyone can direct me to a good EjbQL learning resource,

that would be great. Thanks.


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.