jhomenet.dao.hibernate
Class GenericHibernateDAO<T,ID extends java.io.Serializable>

java.lang.Object
  extended by jhomenet.dao.hibernate.GenericHibernateDAO<T,ID>
All Implemented Interfaces:
GenericDAO<T,ID>
Direct Known Subclasses:
HardwareDataDAOHibernate

public class GenericHibernateDAO<T,ID extends java.io.Serializable>
extends java.lang.Object
implements GenericDAO<T,ID>

Implements the generic CRUD data access operations using Hibernate APIs.

To write a DAO, subclass and parameterize this class with your persistent class. Of course, assuming that you have a traditional 1:1 appraoch for Entity:DAO design.

You have to inject the Class object of the persistent class and a current Hibernate Session to construct a DAO.

Author:
christian.bauer@jboss.com
See Also:
HibernateDAOFactory

Constructor Summary
GenericHibernateDAO(java.lang.Class<T> persistentClass, Session session)
          Default constructor.
 
Method Summary
 java.util.List<T> findAll()
           
protected  java.util.List<T> findByCriteria(Criterion... criterion)
          Use this inside subclasses as a convenience method.
 java.util.List<T> findByExample(T exampleInstance)
           
 T findById(ID id, boolean lock)
           
 java.lang.Class<T> getPersistentClass()
           
protected  Session getSession()
          Get the current Hibernate session.
 T makePersistent(T entity)
           
 void makeTransient(T entity)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericHibernateDAO

public GenericHibernateDAO(java.lang.Class<T> persistentClass,
                           Session session)
Default constructor.

Parameters:
persistentClass -
session -
Method Detail

getSession

protected Session getSession()
Get the current Hibernate session.

Returns:
A reference to the Hibernate session

getPersistentClass

public java.lang.Class<T> getPersistentClass()

findById

public T findById(ID id,
                  boolean lock)
Specified by:
findById in interface GenericDAO<T,ID extends java.io.Serializable>

findAll

public java.util.List<T> findAll()
Specified by:
findAll in interface GenericDAO<T,ID extends java.io.Serializable>

findByExample

public java.util.List<T> findByExample(T exampleInstance)
Specified by:
findByExample in interface GenericDAO<T,ID extends java.io.Serializable>

makePersistent

public T makePersistent(T entity)
Specified by:
makePersistent in interface GenericDAO<T,ID extends java.io.Serializable>

makeTransient

public void makeTransient(T entity)
Specified by:
makeTransient in interface GenericDAO<T,ID extends java.io.Serializable>

findByCriteria

protected java.util.List<T> findByCriteria(Criterion... criterion)
Use this inside subclasses as a convenience method.



Copyright © 2004-2005 David Irwin. All Rights Reserved.