public abstract class BaseService<T> extends Object
Modifier and Type | Field and Description |
---|---|
protected org.hibernate.SessionFactory |
sessionFactory
The session factory of Hibernate.
|
Constructor and Description |
---|
BaseService() |
Modifier and Type | Method and Description |
---|---|
T |
add(T entityModel)
It creates a single new entity in the database and retrieves the created object.
|
T |
findEntityByAttribute(Class<T> entityModelClass,
String columnName,
String columnValue)
It retrieves a single entity when by column name and value.
|
List<T> |
getCollection(Class<T> entityModelClass)
It retrieves all entities from the entity table by the entity model class.
|
T |
getEntityById(Class<T> entityModelClass,
long id)
It retrieves the Hibernate entity model or null by ID and the entity model class.
|
T |
save(T entityModel)
It updates or creates an entity and retrieves the updated object included the ID.
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
It sets the sessionFactory property.
|
T |
update(T entityModel)
It updates an entity what already exists and retrieves the updated object.
|
protected org.hibernate.SessionFactory sessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
sessionFactory
- The session factory of Hibernate.public T add(T entityModel) throws Exception
entityModel
- Any entity model with Hibernate annotations.Exception
public T update(T entityModel) throws Exception
entityModel
- Any entity model with Hibernate annotations.Exception
public T save(T entityModel) throws Exception
entityModel
- Any entity model with Hibernate annotations.Exception
public T getEntityById(Class<T> entityModelClass, long id) throws Exception
entityModelClass
- Any entity model with Hibernate annotations.id
- The ID of any entity.Exception
public T findEntityByAttribute(Class<T> entityModelClass, String columnName, String columnValue)
entityModelClass
- Any entity model with Hibernate annotations.columnName
- The name of the table column.columnValue
- The record in the table.public List<T> getCollection(Class<T> entityModelClass)
entityModelClass
- The class of the Hibernate entity modelCopyright © 2015. All rights reserved.