All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jlot.hibernate.repository.EntityRepositoryHibernate Maven / Gradle / Ivy

There is a newer version: 1.2
Show 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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy