File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes What about findByExample in JPA book? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of C++ Concurrency this week in the C/C++ forum
or Spring Integration in Action in the Spring forum!
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "What about findByExample in JPA book?" Watch "What about findByExample in JPA book?" New topic
Author

What about findByExample in JPA book?

Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 193

Hi Mike and Merrick

Does your book suggest how to achieve findByExample in JPA?
For e.g. if I have an object with 4 instance variables, I fill random 2 of them and try to search. Is it suggested in JPA2 book?

regards
Varun


-Varun -
(My Blog) - Mock Tests
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16394

JPA2 spec now has the ability to create a Criteria query, which allows you to do query by example.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
I'm sorry to say that we didn't actually get to do QBE in JPA 2.0. Criteria API does not have any special operators for it so entity equality is just like in JP QL, based on PK value. Sorry, but hopefully we'll be more successful on that front in the next go-round. For now it is one of those vendor features that every vendor supports, but is not in the spec yet.


-Mike
Pro JPA 2: Mastering the Java Persistence API
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16394

Mike Keith wrote:I'm sorry to say that we didn't actually get to do QBE in JPA 2.0. Criteria API does not have any special operators for it so entity equality is just like in JP QL, based on PK value. Sorry, but hopefully we'll be more successful on that front in the next go-round. For now it is one of those vendor features that every vendor supports, but is not in the spec yet.


Really, I kind of assumed if there was a Criteria object here was QBE. ;)

Mark
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 193

Mike Keith wrote:I'm sorry to say that we didn't actually get to do QBE in JPA 2.0. Criteria API does not have any special operators for it so entity equality is just like in JP QL, based on PK value. Sorry, but hopefully we'll be more successful on that front in the next go-round. For now it is one of those vendor features that every vendor supports, but is not in the spec yet.



Ok, well I think you can give sample code for QBE in JPA 2.0 on web-page dedicated for the book. I am sure this feature comes among the most sought after ones in ORM community.
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
We have tried to keep the book focused on the specification. Since this is a vendor feature then vendor documentation will generally cover this. If you really want a code example that uses QBE, though, here is a sample of using it in the EclipseLink JPA 2.0 reference implementation:
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 193

Mike Keith wrote:We have tried to keep the book focused on the specification. Since this is a vendor feature then vendor documentation will generally cover this. If you really want a code example that uses QBE, though, here is a sample of using it in the EclipseLink JPA 2.0 reference implementation:


Thanks for the code. It looks like there's no vendor neutral way to achieve it.
 
 
subject: What about findByExample in JPA book?
 
MyEclipse, The Clear Choice