views:

1909

answers:

8

I'm looking for the best resources (books, frameworks, tutorials) that will help me get up to speed with JPA. I've been happily using iBatis/JDBC for my persistence needs, so I need resources that will hopefully provide comparable functions on how to do things. e.g. how to I set the isolation level for each transaction ?

I know there might be 10 books on the topic, so hopefully, your recommendation could narrow down to the best 2 books.

Should I start with OpenJPA or are there other opensource JPA frameworks to use ?

P.S. Do suggest if I should learn JPA2 or JPA1 ? My goal ultimately is to be able to write a Google App Engine app (which uses JPA1).

Thanks

Jacque

+8  A: 

There is only one book you truly need to learn JPA - Java Persistence with Hibernate. The book is by Gavin King and there is no online resource that would compare with it in completeness and clarity.

Hibernate would be the most appropriate implementation to use - just because it started it all.

JPA 2 is only in draft so far - there is nothing wrong in JPA 1 that would prevent you from learning enhancements in JPA 2 later - so go for released functionality now.

grigory
That book has some fairly negative reviews on Amazon (some good ones too).
cletus
This book is not trivial and the book is not just about JPA - it also covers Hibernate - both in depth. If you are really determined to understand JPA the book will do magic for you. Regarding Amazon: it's got 25 5-stars - closest "contender" got 14...
grigory
Update (2010) : There are ample JPA2 books around that cover it way better than the referenced book
@user383680: I hope so, the referenced book is on JPA 1.0. It would be nice you had couple of references though. There were few books on the subject back then and none was close.
grigory
+3  A: 

Firstly, I wouldn't use OpenJPA. You'll have an easier time using either:

  • Hibernate: it's the most popular; or
  • EclipseLink: this will be the reference implementation of JPA 2.0 in JEE 6.

TopLink Essentials is the reference implementation of JPA 1.0 but is not as fully-featured as either of the above. Personally I prefer EclipseLink as it has some features that Hibernate simply can't replicate (like batch query loads).

JPA is a rather complicated topic and I don't think I've seen an online tutorial that really does it justice. You shoudl really get a good reference book as you'll often find yourself referring to it.

We had Pro EJB 3: Java Persistence API available when I learnt it and I found that to be a pretty reasonable book.

cletus
Is it because OpenJPA is buggy that you're not recommending it ?
Jacques René Mesrine
Less popular than the other two basically.
cletus
IMO, for targeting cert, its recommended to use openJPA. Otherwise, Hibernate rocks!!
Adeel Ansari
+1 for the book link. Its a recommended read.
Adeel Ansari
Who recommend OpenJPA for cert? And why? It's not even the reference implementation. If you're going to use anything its hould be taht (TopLink Essentials in the case of JPA 1.0)
cletus
OpenJPA is ok. I wouldn't base your choice on popularity. EJB 1.x was popular, that doesn't mean it was any good : )
Jon
When choosing between several otherwise similar things, popularity is an important criteria. See how many ansewrs you get with "I'm having this problem with Hibernate" vs "I'm having this problem with OpenJPA".
cletus
I'd use OpenJPA, and recommend it
+5  A: 

There are plenty of open source JPA implementations; DataNucleus is one of them, the one chosen by Google for its recently released AppEngine.

As far as learning any technology you're best to learn a bit then try things, then learn more etc etc. Consequently start with a simple tutorial just to get the basic idea, e.g http://www.datanucleus.org/products/accessplatform_1_1/guides/jpa/tutorial.html

and then move on to detailed docs once you've got the basic idea http://www.datanucleus.org/products/accessplatform_1_1/jpa/index.html http://www.datanucleus.org/products/accessplatform_1_1/jpa/api.html

The main thing is, stick to the specifications features as much as possible and avoid using things only found in a particular implementation; that way you don't get tied to something and regret it later ;-)

HTH
--Andy (DataNucleus)

DataNucleus
isnt DataNucleus JDO?
instanceofTom
DataNucleus is JDO, JPA, REST and many other things. It is a certified JPA TCK compliant JPA1 implementation hence why I posted here ;-)
DataNucleus
+1  A: 

OpenJPA is an appropriate choice to learn JPA, it's a lot more transparent than Hibernate and the API is often easier to work with. It's much easier to setup and get going as well. Documentation is ok, although it does have a few gotchas (as does every ORM framework if not used with care).

Hibernate has more features than OpenJPA and if you are looking to use it on a medium to large commercial product (on Google App Engine?) then I would certainly choose this instead. It's more stable than OpenJPA also (at least with the version I used - 1.0.2).

The only book I've ever bought on persistence is the Christian Bauer Book:

Java Persistence With Hibernate

It covers the basic theory, JPA and Hibernate in detail, but it's a tough read and I've only really treated it as a reference book. Overall it's OK, and if you want to learn Hibernate in detail then it's the best place to start. It is two years old at present, so there may be other books that are more up to date, e.g:

Harnessing Hibernate

Start with some tutorials before you buy the book - just start by building a simple CRUD app in either Hibernate or OpenJPA and look at the SQL it's using behind the scenes. That's easily the best way to understand what's going on. Hope that helps.

Jon
You cannot use Hibernate on GAE/J ... since that requires BigTable datastore and Hibernate does not persist to that. Neither can you use OpenJPA there. All of your other comments are valid.
... and that piece of information was added to the question AFTER I posted this answer.
Jon
+1  A: 

if you are looking to use it on a medium to large commercial product (on Google App Engine?)

Google App Engine has it's own implementation of JPA using (I believe) Data Nucleus.

Andy Gibson
A: 

The most recent JPA book is: Java Persistence with JPA, by Daoqi Yang, Outskirts Press, published on March 31, 2010. It has very good reviews on amazon.com. The author claims complete coverage of JPA 2.0 adn being concise but with many examples. The author has a website to support this book: http://www.yangdaoqi.info/jpa.html

Hope this helps.

A: 

Sure, JPA 2 Critieria Queries have a learning curve. But you do not have to use it. For many people and many applications, JPQL will be preferred. And that is all you need.