aspose file tools*
The moose likes Object Relational Mapping and the fly likes OpenJPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "OpenJPA" Watch "OpenJPA" New topic
Author

OpenJPA

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Hi All,

Is there a good tutorial for getting started on OpenJPA? From what I have been looking till now, I found tutorials on EclipseLink, TopLink etc JPA implementations but not on OpenJPA. Please, if anybody knows a good tutorial please post it here.

Thanks


Be Humble... Be Nice.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Why should it differ that much? JPA is a standard specification. All of the implementations ought to behave the same. Just get the implementation's JAR file(s), place them in the classpath and do your JPA thing according to a standard JPA tutorial.

Sun at least has one: http://java.sun.com/javaee/5/docs/tutorial/doc/bnbpz.html
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Bauke Scholtz wrote:Why should it differ that much? JPA is a standard specification. All of the implementations ought to behave the same. Just get the implementation's JAR file(s), place them in the classpath and do your JPA thing according to a standard JPA tutorial.

Sun at least has one: http://java.sun.com/javaee/5/docs/tutorial/doc/bnbpz.html


Thanks for replying Bauke. I am starting on implementing one of the JPA implementations and I will take it from there.
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Ok, This tutorial works fine for both JPA and OpenJPA. I just checked. To Use OpenJPA, just select it as the Persistence provider while adding the JPA capabilities.


http://www.myeclipseide.com/documentation/quickstarts/jpa/

One small problem though. Using OpenJPA the update operation's giving the exact results as using JPA with one additional line.

This is the result I am getting using each of them:


OpenJPA Result:
--------------

Apr 5, 2009 9:47:43 PM com.aa.OpenJPA.EntityManagerHelper log
INFO: finding Productline instance with id: Men's Shoes
94 SampleOpenJPAProjectPU INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.0
203 SampleOpenJPAProjectPU INFO [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.DerbyDictionary".
547 SampleOpenJPAProjectPU INFO [main] openjpa.Enhance - Creating subclass for "[class com.aa.OpenJPA.Productline]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
*REVISED* Product Line [productLine=Men's Shoes, textDescription=Shoes for men., image=null, html description=<strong>Men's Shoes</strong>]



JPA Result:
----------

Apr 5, 2009 9:45:20 PM com.aa.jpa.EntityManagerHelper log
INFO: finding Productline instance with id: Men's Shoes
[TopLink Info]: 2009.04.05 09:45:21.171--ServerSession(7578443)--TopLink, version: Oracle TopLink Essentials - 2.0 (Build b40-rc (03/21/2007))
[TopLink Info]: 2009.04.05 09:45:21.421--ServerSession(7578443)--file:/D:/JPA%20Eclipse/JPA%20MyEclipse%20Workspace/SampleJPAProject/bin/-SampleJPAProjectPU login successful
*REVISED* Product Line [productLine=Men's Shoes, textDescription=Shoes for men., image=null, html description=<strong>Men's Shoes</strong>]



I have bolded the line which is different. I have read previously that we have to use some kind of enhancer while using OpenJPA. Is this caused because of that?

Note: Yes, the error's caused because of that. Detailed information is here. http://openjpa.apache.org/builds/1.0.0/apache-openjpa-1.0.0/docs/manual/ref_guide_pc_enhance.html

Thanks.
Rick Curtis
Greenhorn

Joined: Apr 23, 2009
Posts: 1
Arjun -
The message Creating subclass for... is because by default MyEclipse doesn't run the OpenJPA enhancer. Enhancing your Entity classes is very important when using OpenJPA. I wrote a blog posting that talks about OpenJPA enhancement here and another about using an Eclipse builder to enhance when running inside (My)Eclipse.

Hopefully this helps!

-Rick
Arjun Reddy wrote:Ok, This tutorial works fine for both JPA and OpenJPA. I just checked. To Use OpenJPA, just select it as the Persistence provider while adding the JPA capabilities.


http://www.myeclipseide.com/documentation/quickstarts/jpa/

One small problem though. Using OpenJPA the update operation's giving the exact results as using JPA with one additional line.

This is the result I am getting using each of them:

.....
547 SampleOpenJPAProjectPU INFO [main] openjpa.Enhance - Creating subclass for "[class com.aa.OpenJPA.Productline]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
*REVISED* Product Line [productLine=Men's Shoes, textDescription=Shoes for men., image=null, html description=<strong>Men's Shoes</strong>]

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Rick Curtis wrote:Arjun -
The message Creating subclass for... is because by default MyEclipse doesn't run the OpenJPA enhancer. Enhancing your classes is very important when using OpenJPA. I wrote a blog posting that talks about OpenJPA enhancement here and another about using an Eclipse builder to enhance when running inside Eclipse.

Hopefully this helps!

-Rick
Arjun Reddy wrote:Ok, This tutorial works fine for both JPA and OpenJPA. I just checked. To Use OpenJPA, just select it as the Persistence provider while adding the JPA capabilities.


http://www.myeclipseide.com/documentation/quickstarts/jpa/

One small problem though. Using OpenJPA the update operation's giving the exact results as using JPA with one additional line.

This is the result I am getting using each of them:

.....
547 SampleOpenJPAProjectPU INFO [main] openjpa.Enhance - Creating subclass for "[class com.aa.OpenJPA.Productline]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead.
*REVISED* Product Line [productLine=Men's Shoes, textDescription=Shoes for men., image=null, html description=<strong>Men's Shoes</strong>]



Thanks for the reply Rick. I will check it out.

-Arjun
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: OpenJPA