This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes What about findByExample in JPA book? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
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: 211
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) - Online Certifications - Webner Solutions
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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: 17250
    
    6

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: 211
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: 211
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.
 
GeeCON Prague 2014
 
subject: What about findByExample in JPA book?