-->
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 by Example
PostPosted: Wed Jun 23, 2004 8:14 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Example queries
"Version properties, identifiers and associations are ignored."

What is than the best way to search by example when you have associations?

For example: we have class Book which holds many-to-one Author object

public class Book {

private int m_book_id;
private String m_title;
private Author m_author;
...

public Author getAuthor() {
return m_author;
}

public void setAuthor(Author author) {
m_author = author;
}

...
}

So if I would like to find all Books written by exact Author, what should I do, so that I don't have to write HQL?


Author author = ... load / get exact Author
Book book - new Book();
book.setAuthor(author);
Example example = Example.create(book);
List list = session.createCriteria(Book.class).add(example).list(); //#1

OK, as written "associations are ignored", so #1 wouldn't include author field in query, and I would get all books.

Is this the best solution:
List list = session.createCriteria(Book.class).add(Expression.eq("author", author)).list(); //#2

What is the reason #1 isn't implemented?

Thnx, Ales

_________________
--------------------------------
Ales Justin
JBoss, a division of Red Hat


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 20, 2004 5:05 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
I had the same problem, sort of frustrating

I don't know the reason #1 isn't implemented, but I made a change to Example.java (hibernate2 src) to make it work. I don't think Gavin wants associations to be considered in query by example.

Gavin's response:
http://forum.hibernate.org/viewtopic.ph ... highlight=


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 21, 2004 4:20 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
To toastchee:

Did you fix the Example source or did you extend it?
Can you please send me this fixed version.

Thanx,
Ales

_________________
--------------------------------
Ales Justin
JBoss, a division of Red Hat


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 21, 2004 5:39 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
I fixed the source, but my patch was rejected by Gavin. Would you mind contacting Gavin and asking him to reconsider? :-)


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.