-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need help from seniors on Hibernate Criteria Join
PostPosted: Thu Nov 12, 2009 7:13 am 
Newbie

Joined: Sat Jun 27, 2009 12:20 am
Posts: 1
Hi,

I have two tables related with one - to - many association (One Invoice can have many Invoice States).

INVOICE (invoiceNum(PK),amount, date) and INVOICE_STATE (id(PK),invoiceNum, type, value)

The join is based on invoiceNum. I need all the invoices from table Invoice having type = "INVACC" and value = "2BP".

I tried following but i get all the results :(

Code:
        return getSession().createCriteria(Invoice.class).createCriteria("invoiceStateList", "state").add(
                Expression.eq("state.type", "INVACC")).add(
                        Expression.eq("state.value", "2BP")).list();


Please help.


Top
 Profile  
 
 Post subject: Re: Need help from seniors on Hibernate Criteria Join
PostPosted: Thu Nov 12, 2009 11:32 am 
Beginner
Beginner

Joined: Tue Oct 30, 2007 7:57 am
Posts: 47
You may try this. You create the inner criteria, and add conditions to it. Then execute list() over the outer criteria

Code:
        Criteria invoiceCriteria = getSession().createCriteria(Invoice.class);
        Criteria invoiceCriteriaState = invoiceCriteria.createCriteria("invoiceStateList");
        invoiceCriteriaState.add(Expression.eq("type", "INVACC")).add(Expression.eq("value", "2BP"));
        return invoiceCriteria.list();


The qury will return all invoices with at leat one state that meets your requirements


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