Package org.hibernate
Class Hibernate
- java.lang.Object
-
- org.hibernate.Hibernate
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Hibernate.CollectionInterface<C>
Operations for obtaining references to persistent collections of a certain type.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <U> Hibernate.CollectionInterface<Collection<U>>
bag()
Obtain an instance ofHibernate.CollectionInterface
representing persistent bags of a given element type.static void
close(Iterator iterator)
Close anIterator
instances obtained fromorg.hibernate.Query#iterate()
immediately instead of waiting until the session is closed or disconnected.static <C> Hibernate.CollectionInterface<C>
collection(Class<C> collectionClass)
Obtain an instance ofHibernate.CollectionInterface
representing persistent collections of the given type.static <E> E
createDetachedProxy(SessionFactory sessionFactory, Class<E> entityClass, Object id)
Obtain a detached, uninitialized reference (a proxy) for a persistent entity with the given identifier.static Class
getClass(Object proxy)
Get the true, underlying class of a proxied persistent class.static LobCreator
getLobCreator(SessionImplementor session)
Obtain a lob creator for the given session.static LobCreator
getLobCreator(SharedSessionContractImplementor session)
Obtain a lob creator for the given session.static LobCreator
getLobCreator(Session session)
Obtain a lob creator for the given session.static void
initialize(Object proxy)
Force initialization of a proxy or persistent collection.static boolean
isInitialized(Object proxy)
Check if the proxy or persistent collection is initialized.static boolean
isPropertyInitialized(Object proxy, String propertyName)
Check if the property is initialized.static <U> Hibernate.CollectionInterface<List<U>>
list()
Obtain an instance ofHibernate.CollectionInterface
representing persistent lists of a given element type.static <U,V>
Hibernate.CollectionInterface<Map<U,V>>map()
Obtain an instance ofHibernate.CollectionInterface
representing persistent maps of a given key and value types.static <U> Hibernate.CollectionInterface<Set<U>>
set()
Obtain an instance ofHibernate.CollectionInterface
representing persistent sets of a given element type.static <U,V>
Hibernate.CollectionInterface<Map<U,V>>sortedMap()
Obtain an instance ofHibernate.CollectionInterface
representing sorted persistent maps of a given key and value types.static <U> Hibernate.CollectionInterface<SortedSet<U>>
sortedSet()
Obtain an instance ofHibernate.CollectionInterface
representing sorted persistent sets of a given element type.static Object
unproxy(Object proxy)
Unproxies aHibernateProxy
.static <T> T
unproxy(T proxy, Class<T> entityClass)
Unproxies aHibernateProxy
.
-
-
-
Method Detail
-
initialize
public static void initialize(Object proxy) throws HibernateException
Force initialization of a proxy or persistent collection. Note: This only ensures initialization of a proxy object or collection; it is not guaranteed that the elements INSIDE the collection will be initialized/materialized.- Parameters:
proxy
- a persistable object, proxy, persistent collection or null- Throws:
HibernateException
- if we can't initialize the proxy at this time, eg. the Session was closed
-
isInitialized
public static boolean isInitialized(Object proxy)
Check if the proxy or persistent collection is initialized.- Parameters:
proxy
- a persistable object, proxy, persistent collection or null- Returns:
- true if the argument is already initialized, or is not a proxy or collection
-
getClass
public static Class getClass(Object proxy)
Get the true, underlying class of a proxied persistent class. This operation will initialize a proxy by side-effect.- Parameters:
proxy
- a persistable object or proxy- Returns:
- the true class of the instance
- Throws:
HibernateException
-
getLobCreator
public static LobCreator getLobCreator(Session session)
Obtain a lob creator for the given session.- Parameters:
session
- The session for which to obtain a lob creator- Returns:
- The log creator reference
-
getLobCreator
public static LobCreator getLobCreator(SharedSessionContractImplementor session)
Obtain a lob creator for the given session.- Parameters:
session
- The session for which to obtain a lob creator- Returns:
- The log creator reference
-
getLobCreator
public static LobCreator getLobCreator(SessionImplementor session)
Obtain a lob creator for the given session.- Parameters:
session
- The session for which to obtain a lob creator- Returns:
- The log creator reference
-
close
public static void close(Iterator iterator) throws HibernateException
Close anIterator
instances obtained fromorg.hibernate.Query#iterate()
immediately instead of waiting until the session is closed or disconnected.- Parameters:
iterator
- an Iterator created by iterate()- Throws:
HibernateException
- Indicates a problem closing the Hibernate iterator.IllegalArgumentException
- If the Iterator is not a "Hibernate Iterator".- See Also:
Query#iterate()
-
isPropertyInitialized
public static boolean isPropertyInitialized(Object proxy, String propertyName)
Check if the property is initialized. If the named property does not exist or is not persistent, this method always returns true.- Parameters:
proxy
- The potential proxypropertyName
- the name of a persistent attribute of the object- Returns:
- true if the named property of the object is not listed as uninitialized; false otherwise
-
unproxy
public static Object unproxy(Object proxy)
Unproxies aHibernateProxy
. If the proxy is uninitialized, it automatically triggers an initialization. In case the supplied object is null or not a proxy, the object will be returned as-is.- Parameters:
proxy
- theHibernateProxy
to be unproxied- Returns:
- the proxy's underlying implementation object, or the supplied object otherwise
-
unproxy
public static <T> T unproxy(T proxy, Class<T> entityClass)
Unproxies aHibernateProxy
. If the proxy is uninitialized, it automatically triggers an initialization. In case the supplied object is null or not a proxy, the object will be returned as-is.- Parameters:
proxy
- theHibernateProxy
to be unproxiedentityClass
- the entity type- Returns:
- the proxy's underlying implementation object, or the supplied object otherwise
-
createDetachedProxy
public static <E> E createDetachedProxy(SessionFactory sessionFactory, Class<E> entityClass, Object id)
Obtain a detached, uninitialized reference (a proxy) for a persistent entity with the given identifier. The returned proxy is not associated with any session, and cannot be initialized by callinginitialize(Object)
. It can be used to represent a reference to the entity when working with a detached object graph.- Parameters:
sessionFactory
- the session factory with which the entity is associatedentityClass
- the entity classid
- the id of the persistent entity instance- Returns:
- a detached uninitialized proxy
-
bag
public static <U> Hibernate.CollectionInterface<Collection<U>> bag()
Obtain an instance ofHibernate.CollectionInterface
representing persistent bags of a given element type.- Type Parameters:
U
- the element type
-
set
public static <U> Hibernate.CollectionInterface<Set<U>> set()
Obtain an instance ofHibernate.CollectionInterface
representing persistent sets of a given element type.- Type Parameters:
U
- the element type
-
list
public static <U> Hibernate.CollectionInterface<List<U>> list()
Obtain an instance ofHibernate.CollectionInterface
representing persistent lists of a given element type.- Type Parameters:
U
- the element type
-
map
public static <U,V> Hibernate.CollectionInterface<Map<U,V>> map()
Obtain an instance ofHibernate.CollectionInterface
representing persistent maps of a given key and value types.- Type Parameters:
U
- the key typeV
- the value type
-
sortedSet
public static <U> Hibernate.CollectionInterface<SortedSet<U>> sortedSet()
Obtain an instance ofHibernate.CollectionInterface
representing sorted persistent sets of a given element type.- Type Parameters:
U
- the element type
-
sortedMap
public static <U,V> Hibernate.CollectionInterface<Map<U,V>> sortedMap()
Obtain an instance ofHibernate.CollectionInterface
representing sorted persistent maps of a given key and value types.- Type Parameters:
U
- the key typeV
- the value type
-
collection
public static <C> Hibernate.CollectionInterface<C> collection(Class<C> collectionClass)
Obtain an instance ofHibernate.CollectionInterface
representing persistent collections of the given type.- Parameters:
collectionClass
- the Java class object representing the collection type
-
-