-->
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.  [ 2 posts ] 
Author Message
 Post subject: Session or EntityManager
PostPosted: Fri Sep 18, 2009 2:55 am 
Newbie

Joined: Fri Sep 18, 2009 2:06 am
Posts: 1
I'm new to persistence frameworks, and wonder whether to use Java Persistence API or Hibernate in my Java Desktop application.

JPA:
Code:
EntityManager em = Persistence.createEntityManagerFactor ("MyProjectPU").createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(myObject);
tx.commit();


Hibernate:
Code:
Session session = SessionFactoryUtil.getInstance().getCurrentSession();
Transaction tx = session.beginTransaction();     
session.save(myObject);     
tx.commit();


What's the difference between these two ways of saving an object? Why should I use JPA? Why should I use Hibernate?

Thanks in advance!

Trygve


Top
 Profile  
 
 Post subject: Re: Session or EntityManager
PostPosted: Fri Sep 18, 2009 7:29 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, as you are finding out, the two approaches are very similar! They both are essentially JPA implementers.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.