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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "difference between session and entitymanager" Watch "difference between session and entitymanager" New topic
Author

difference between session and entitymanager

jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
hi

guys i am using session and entitymanager, but i can not tell the difference between them

some one please explains to me little bit
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

Jim,

If you're talking about Hibernate, then the EntityManager and the Hibernate Session are are equivalent. You use the EntityManager if you want to use the Java Persistence API, and Hibernate's Session if you're using Hibernate's API.


There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
thank you for you help

but i still have one question:

is the entitymanager used to interact with the JEB3?

but the session does not?
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

EJB3 is a pluggable architecture, so you need to be clear on what element you mean.

EntityManager is the Hibernate JPA (Java Persitence API) implementation. If you want to use the JPA instead of Hibernate's Core, then use EntityManager.

Hibernate Annotations implement the JPA annotations, plus have additional annotations for Hibernate specific features.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

What you will also see, is that Hibernate is just wrapping their Session object in their EntityManager implementation. Which is why you can always get a Session object from your EntityManager, is you want to go to the Session api.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
thank you for you help

i believe that it is what i want to know

so based on what you said

entitymanager should be more powerful than session

since session is wrapped in entitymanager implementation, so entitymanager has everything session has, and owns some extra stuff.

am i correct?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by jim li:
thank you for you help

i believe that it is what i want to know

so based on what you said

entitymanager should be more powerful than session

since session is wrapped in entitymanager implementation, so entitymanager has everything session has, and owns some extra stuff.

am i correct?


Actually the complete opposite.

Session has more stuff to it, the EntityManager is a specification api, and the spec doesn't cover everything that Hibernate can do, so only certain methods of a Session object is called, not all of them.

Mark
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
thank you
Tom Lang
Greenhorn

Joined: Dec 14, 2011
Posts: 1
Thank You! Finally a post which explains the difference between Entity Manager and Hibernate Session (org.hibernate.Session).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between session and entitymanager
 
Similar Threads
J2EE
Session Facade vs Session Bean
Difference between UserTransaction and EntityTransaction?
Session Facade vs Session Bean
SCEA Part2 Using DAO?