-->
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: Using criteria API two join tables
PostPosted: Mon Oct 18, 2010 11:06 pm 
Newbie

Joined: Mon Oct 18, 2010 10:34 pm
Posts: 1
Hello Friends,

I am new to hibernate and this forum. I would really appreciate if someone could help me solve the problem.I have a sql query

Code:
select  p.id, p.start, p.end from purchase p, account a where p.eid =940 and p.id=a.id  and a.status = 'reference';


I learnt from the tutorials, for the sql query below the following is the criteria query

Code:
SELECT B.*,P.* FROM BANK B, PURCHASE P WHERE B.ACCNO=P.ACCNO;

Code:
List rs = session.createCriteria(Bank.class)     

      .setFetchMode("Purchase",FetchMode.JOIN)     

        .list();


So for my sql statement can someone please tell me if my criteria query is right?

Code:
List rs = session.createCriteria(purchase.class)     

      .setFetchMode("account",FetchMode.JOIN)   
      .add(Restrictions.eq("eid",new Integer(940)
      .add(Restrictions.eq("status","reference")
      .setProjection(Projections.propertyList()
            .add(Projections.property("id"))
            .add(Projections.property("start"))
            .add(Projections.property("end"))

        .list();


Thanks in advance


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.