-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: JPA - trying to understand hibernate vs JPA
PostPosted: Mon Jul 06, 2009 4:11 pm 
Newbie

Joined: Mon Jul 06, 2009 10:38 am
Posts: 17
I am new to hibernate but I have been reading a fair bit about it. The problem I'm struggling with is understanding how different technologies "implement" the JPA standard. I am using annotations with hibernate by using the sessionFactory. If I were to use the entityManager instead and mapped it in persistense.xml, would I then have a hibernate implementation of JPA?

I see that there are different persistent engines such as TopLink and that you specify these to connect to your database in persistence.xml or hibernate in the hibernate.cfg.xml file.

what implementation would the following persistence.xml give us?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<class>com.foo.Greeting</class>
<properties>
<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/test"/>
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.password" value=""/>
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>

I would rather use the JPA specification if it's more portable but to connect to the database and map to the database it appears you need some kind of persistence engine such as hibernate or TopLink, can anyone help me understand the differences between these engines. I want my code to be portable so I was thinking if I use EJB3 instead of Hibernate it would give me this. Any help is appreciated.


Top
 Profile  
 
 Post subject: Re: JPA - trying to understand hibernate vs JPA
PostPosted: Tue Jul 07, 2009 3:01 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Hi,

If you stick with the JPA APIs as you have described, then you should be able to switch between implementations if necessary.

The blog post at: http://terrazadearavaca.blogspot.com/2008/12/jpa-implementations-comparison.html shows one person's attempt at comparing JPA implementations in 2008.

I've used the Eclipselink JPA implementation in the past and see that it is still well supported - perhaps a better choice than Toplink?

DataNucleus (http://www.datanucleus.com/) has been around for a while (previously known as JPox) and provides an implementation of JPA. (Google AppEngine uses DataNucleus - see http://www.datanucleus.com/news/google_app_engine.html).


--
Stephen Souness


Blog: http://elegant-solutions.blogspot.com/


Top
 Profile  
 
 Post subject: what makes it a JPA API?
PostPosted: Tue Jul 07, 2009 5:24 pm 
Newbie

Joined: Mon Jul 06, 2009 10:38 am
Posts: 17
In my example was it just the fact that I used persistence.xml and setup the XML <provider> to TopLink that made it a JPA API? That's the part I guess I'm having trouble understanding. What makes something a JPA API? Is it because I used the following:
Code:
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>

I have seen situations where they use persistence.xml and used a hibernate engine to connect to the JDBC (this was done in persistence.xml). Is that considered a JPA ATI since they used EntityManager? Sorry for the questions, just trying to understand.


Top
 Profile  
 
 Post subject: hibernate - Hibernate API vs Hibernate JPA API
PostPosted: Tue Jul 07, 2009 5:33 pm 
Newbie

Joined: Mon Jul 06, 2009 10:38 am
Posts: 17
Ok, I guess the source to all my confusion stems from trying to understand the API I am using versus the JPA stuff out there. Right now I am using Hibernate and have it configured using hibernate.cfg.xml and am using a sessionFactory in my hibernateUtil.java wrapper to connect to my session. Is this the JPA or Hibernate implementation?

If I were to configure persistence.xml to use EntityManager with hibernate using Hibernate EntityManager, is this then the JPA API of hibernate?

This is the part that's confusing..

thanks.


Top
 Profile  
 
 Post subject: Re: JPA - trying to understand hibernate vs JPA
PostPosted: Tue Jul 07, 2009 8:31 pm 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
A few easy ways to tell whether your model is pure JPA, or is Hibernate-specific:
- If you are using SessionFactory and Session then it is Hibernate
- If you are using EntityManagerFactory and EntityManager then it is JPA
- If your code is importing anything specific to Hibernate, then it is not purely JPA

In theory you should be able to keep all references to Hibernate out of your Java classes if you are using JPA, but in reality you will most likely be tempted to use something beyond the capabilities of JPA 1.0 - probably via an annotation - provided by whichever JPA vendor you go with.


--
Stephen Souness



blog: http://elegant-solutions.blogspot.com/


Top
 Profile  
 
 Post subject: Thanks a lot stephen
PostPosted: Wed Jul 08, 2009 10:07 am 
Newbie

Joined: Mon Jul 06, 2009 10:38 am
Posts: 17
I think I'm following you on this. I found an interesting article online that allows you to take your
hibernate config file (hibernate.cfg.xml) and easily switch from hibernate API-> JPA API

http://courses.coreservlets.com/Course-Materials/pdf/hibernate/10-hibernate-JPA.pdf

so it does come down to the EntityManager vs the Session. I can see that there are a couple of differences between the two. Our current setup is Tomcat 6.0 + Hibernate 3.x + MySQL. Just out of curiosity, does this setup seem reasonable for a small webapp? Thanks again.


Top
 Profile  
 
 Post subject: Re: JPA - trying to understand hibernate vs JPA
PostPosted: Wed Jul 08, 2009 11:26 am 
Regular
Regular

Joined: Fri Jan 30, 2009 10:10 am
Posts: 74
Location: London
Hi,

Tomcat 6, Hibernate 3 and a recent version of MySQL should be a reasonable stack for the sort of system you have in mind.

You may also want to consider pooling JDBC connections, and what to use for second-level caching.


--
Stephen Souness



blog: http://elegant-solutions.blogspot.com/


Top
 Profile  
 
 Post subject: one last question..
PostPosted: Wed Jul 08, 2009 12:09 pm 
Newbie

Joined: Mon Jul 06, 2009 10:38 am
Posts: 17
I'm trying to figure out how to configure my persistence.xml, maybe someone here can help. My current hibernate.cfg.xml is the following:
Code:
<session-factory>
      <!-- Database connection settings -->
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql://localhost:3306/chamarel</property>
      <property name="connection.username">root</property>
      <property name="connection.password">password</property>
      <!-- JDBC connection pool (use the built-in) -->
      <property name="connection.pool_size">1</property>
      <!-- SQL dialect -->
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!-- Enable Hibernate's automatic session context management -->
      <property name="current_session_context_class">thread</property>
      <!-- Disable the second-level cache -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">true</property>
      <property name="format_sql">true</property>
      <!-- Drop and re-create the database schema on startup -->
      <property name="hbm2ddl.auto">none</property>
</session-factory>


How would I configure my persistence.xml? Specifically concerned with what I should use for the <provider> field and what my <property name> should be. Do I need to install anything such as hibernate EntityManager? Thanks.


Top
 Profile  
 
 Post subject: Re: JPA - trying to understand hibernate vs JPA
PostPosted: Thu Jul 09, 2009 4:13 am 
Newbie

Joined: Wed Jun 03, 2009 2:21 am
Posts: 5
Hi,

Iam using EntityManagerFactory and EntityManager and using config files for defining the model classes, instead of annotated classes. In this case can i say iam using hibernate JPA and not hibernate Native ?

Please help!!

Regards,
Sajitha


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.