-->
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.  [ 4 posts ] 
Author Message
 Post subject: Query on CollectionOfElements
PostPosted: Thu Nov 13, 2008 11:48 am 
Newbie

Joined: Thu Nov 13, 2008 11:26 am
Posts: 3
Hi,

I'm trying to find out if it's possible to query on a collection of value components with JPA.

Take the classic Invoice / Detail example mapped as follow :

Code:
@Entity
public class Invoice {
    @org.hibernate.annotations.CollectionOfElements
    private List<InvoiceLine> invoiceLines;
   
    ...
}


Code:
@Embeddable
public class InvoiceLine {
    @org.hibernate.annotations.Parent
    private Invoice invoice;
   
    @ManyToOne
    private Product product;
   
    ...
}


I want to query for all invoices that contain a certain product...

I know that the CollectionOfElements is not part of JPA but maybe Hibernate has a native solution for that kind of situation (which doesn't seem that exotic to me).

Any help would be appreciated...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2008 2:15 pm 
Newbie

Joined: Thu Nov 13, 2008 11:26 am
Posts: 3
No replies and I still haven't figured it out.

Anyone would know how this could be done in native Hibernate (either with HQL or Criteria)?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2008 4:02 am 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
Have you tried this?

Quote:
@NamedQuery(name="InvoiceLine .findByProduct",
query="SELECT DISTINCT i FROM Invoice AS i JOIN i.invoiceLines AS L WHERE L.product= :product"),


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2008 5:28 pm 
Newbie

Joined: Thu Nov 13, 2008 11:26 am
Posts: 3
Great!!! That seams to be working!!!

Thanks :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.