info.joseluismartin.hibernate
Class HibernateUtils

java.lang.Object
  extended by info.joseluismartin.hibernate.HibernateUtils

public abstract class HibernateUtils
extends Object

Hibernate Utility library

Author:
Jose Luis Martin - (jlm@joseluismartin.info)

Field Summary
static int DEFAULT_DEPTH
           
 
Constructor Summary
HibernateUtils()
           
 
Method Summary
static Example excludeBooleanFields(Object instance)
          Get a hibernate Example object that excludes zeroes values and excludes all boolean -primitive and wrapper class- attributes of a given object.
static String findAliasForPropertyPath(Criteria criteria, String propertyPath)
          Return a existing alias for propertyPath on Criteria or null if none
static Set<String> getFieldNamesByType(Object obj, Class<?> type)
          Get all name attributes from a object that are of the given class
static String getIdentifierPropertyName(SessionFactory sessionFactory, Object obj)
          Gets the identifier property name of persistent object
static void initialize(SessionFactory sessionFactory, Object obj)
          Initialize a Object for use with closed sessions, Use with care, will recurse on all properties.
static void initialize(SessionFactory sessionFactory, Object obj, int depth)
          Initialize a Object for use whith closed session.
static void initialize(Session session, Object o)
           
static void initializeCollection(Collection collection, Session session)
          Initialize Collection (detached or not)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DEPTH

public static final int DEFAULT_DEPTH
See Also:
Constant Field Values
Constructor Detail

HibernateUtils

public HibernateUtils()
Method Detail

initialize

public static void initialize(SessionFactory sessionFactory,
                              Object obj,
                              int depth)
Initialize a Object for use whith closed session. Will recurse on properties at maximum of n depth.

Parameters:
sessionFactory - the Hibernate SessionFactory to use
obj - Object to initialize
depth - max depth in recursion

initialize

public static void initialize(SessionFactory sessionFactory,
                              Object obj)
Initialize a Object for use with closed sessions, Use with care, will recurse on all properties.

Parameters:
sessionFactory - the hibernate SessionFactory
obj - persistent object to initialize

initializeCollection

public static void initializeCollection(Collection collection,
                                        Session session)
Initialize Collection (detached or not)

Parameters:
collection - collection to initialize
session - Session to use for initialization

initialize

public static void initialize(Session session,
                              Object o)
Parameters:
session -
o -

getIdentifierPropertyName

public static String getIdentifierPropertyName(SessionFactory sessionFactory,
                                               Object obj)
Gets the identifier property name of persistent object

Parameters:
sessionFactory - the hibernate SessionFactory
obj - the persistent object
Returns:
the identifier property name

getFieldNamesByType

public static Set<String> getFieldNamesByType(Object obj,
                                              Class<?> type)
Get all name attributes from a object that are of the given class

Parameters:
obj - Object to get fields
type - type of the class to find.
Returns:
name attributes with the class type specified

excludeBooleanFields

public static Example excludeBooleanFields(Object instance)
Get a hibernate Example object that excludes zeroes values and excludes all boolean -primitive and wrapper class- attributes of a given object.

Parameters:
instance - given object for a build a Example object.
Returns:
a hibernate Example object.

findAliasForPropertyPath

public static String findAliasForPropertyPath(Criteria criteria,
                                              String propertyPath)
Return a existing alias for propertyPath on Criteria or null if none

Parameters:
criteria - Hibernate Criteria
propertyPath - the property path
Returns:
alias or null if none


Copyright © 2012 JDAL. All Rights Reserved.