Reputation: 4475
In Hibernate 4.3 , load()
from session
returns the proxy object with lazy loading and get()
returns the object if it exists or null
if it doesn't. But here and here its mentioned that getReference()
returns a proxy object and load()
returns an object with initialized data.
On Further googling i realized that these methods are from IdentifierLoadAccess Interface. so my questions are
getReference()
is functionally equal to load()
from session and this load()
is equal to get()
from session
? Upvotes: 4
Views: 4525
Reputation: 90527
EntityManager#getReference()
is functionally equal to session#load()
. This can be verified by the hibernate 's EntityManager implementation ( AbstractEntityManagerImpl
) which delegates the work to session#load().
session#load()
and session#get()
have some difference in behaviour . For details , please see this.
IdentifierLoadAccess
is under the package org.hibernate
. So it is Hibernate native API . All interfaces defined by JPA specification are under the package javax.persistence
.
JPA are standard Java API for persistence which means if your application only uses JPA API , theoretically , it is portable between different JPA providers. You application would work even you change to use other JPA provider only switch to other JavaEE application server.
Upvotes: 3
Reputation: 692071
The package of IdentifierLoadAccess
is org.hibernate
. It's thus not part of the JPA spec. Otherwise, it would be under javax.persistence
.
IdentifierLoadAccess.getReference()
is, as the example suggests, equivalent to EntityManager.getReference()
, and also to the old, badly named Session.load()
.
IdentifierLoadAccess.load()
is, as the example suggests, equivalent to EntityManager.find()
, and also to the Session.get()
.
As far as I understand, this IdentifierLoadAccess
interface and the methods it contains are useful to provide a consistent way to load/getReference to entities between IDs and simple natural IDs (and to a lesser extent, natural IDs). See all the methods starting by by
in the Session api doc.
Upvotes: 2