Class GenericDao<T>

java.lang.Object
me.nickhanson.codeforge.persistence.GenericDao<T>

public class GenericDao<T> extends Object
Generic, concrete data helper used by DAOs to perform common CRUD operations with Hibernate SessionFactory. This is intentionally not a Spring bean to match the class pattern used in the project.
Author:
Nick Hanson
  • Constructor Details

    • GenericDao

      public GenericDao(Class<T> type)
  • Method Details

    • getById

      public T getById(Long id)
      Get entity by its primary key ID.
      Parameters:
      id - the primary key ID
      Returns:
      the entity instance or null if not found
    • getAll

      public List<T> getAll()
      Get all entities of type T, ordered by ID ascending.
      Returns:
      list of all entities
    • saveOrUpdate

      public void saveOrUpdate(T entity)
      Save or update the given entity.
      Parameters:
      entity - the entity to save or update
    • delete

      public void delete(T entity)
      Delete the given entity.
      Parameters:
      entity - the entity to delete
    • findByPropertyEqual

      public List<T> findByPropertyEqual(String property, Object value)
      Find entities where a property equals a given value.
      Parameters:
      property - the property name
      value - the value to match
      Returns:
      list of matching entities