-->
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: Associations with Criteria
PostPosted: Wed May 05, 2010 6:56 am 
Newbie

Joined: Sat Apr 10, 2010 9:12 am
Posts: 6
hi everyone,

here is what I want to do I have two table on my data base
Book(bookId,bookTitle,authorId)
Author(AuthorId,AuthorName)

I want to get list of books that have a particular author (identified by name)
here is what I thought of:
Code:
         
         Criteria criteria=session.createCriteria(Author.class);         
         
          criteria.add(Restrictions.ilike("AuthorName", StringUtil.lowerCase("ABC")));
         List lauthor=criteria.list();
                  
         Criteria criteriaB=session.createCriteria(Book.class);
                                    
         for (int i = 0; i < lauthor.size(); i++)
         {
            Author ath = (Author)lauthor.get(i);
                        
                  criteriaB.add(Restrictions.ilike("AuthorId", StringUtil.lowerCase(ath.getAuthorId())));
         }
       
         List lfinalB=criteriaB.list();


Is there a better solution??

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.