org.jlot.hibernate.repository.EntityRepositoryHibernate Maven / Gradle / Ivy
The newest version!
package org.jlot.hibernate.repository;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import org.jlot.hibernate.orm.PersistableEntity;
import org.jlot.hibernate.repository.api.EntityRepository;
public abstract class EntityRepositoryHibernate extends RepositoryHibernate implements EntityRepository
{
@Override
public T load ( Integer id )
{
return getSession().load(getGenericClass(), id);
}
@SuppressWarnings("unchecked")
protected Class getGenericClass ( )
{
Class result = null;
Type type = this.getClass().getGenericSuperclass();
if (type instanceof ParameterizedType)
{
ParameterizedType pt = (ParameterizedType) type;
Type[] fieldArgTypes = pt.getActualTypeArguments();
result = (Class) fieldArgTypes[0];
}
return result;
}
}