Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What about findByExample in JPA book?

 
Varun Chopra
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPA2 spec now has the ability to create a Criteria query, which allows you to do query by example.

Mark
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic