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: How to create Criteria for the query: indirectly-related
PostPosted: Sun Aug 09, 2009 12:51 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Hello, I need some help to create criteria:

3 class ( tables):

Book (title, Author)
Author (name)
Dept (name, Author)

Book --> Author
Dept --> Author

public class Book {
....
public Author getAuthor();
}


public class Author {
....
public String getName();
}

public class Dept {
public String getName();
public Author getAuthor();

}

In our app, there is no mapping from Author to Dept.

List all books and their departments that wrote the books

Book Dept
-----------

How to use Criteria API to create such a query?

Thanks,
Dave


Top
 Profile  
 
 Post subject: Re: How to create Criteria for the query: indirectly-related
PostPosted: Mon Aug 10, 2009 7:32 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Do you even need the criteria API? http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=09howtousethecriteriaapi

Why not just get the books, and then do the old book.getDepartments(), which will return to you all of the departments associated with the book?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.