portable way to unwrap the session (#266)

This commit is contained in:
Athou
2013-06-07 15:08:10 +02:00
parent 4edb481fea
commit fe9797bd83
2 changed files with 2 additions and 6 deletions

View File

@@ -6,7 +6,6 @@ import javax.persistence.PersistenceContext;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.EntityManagerImpl;
import org.hibernate.stat.Statistics;
@Singleton
@@ -72,8 +71,7 @@ public class MetricsBean {
}
public String getCacheStats() {
EntityManagerImpl impl = (EntityManagerImpl) em.getDelegate();
Session session = impl.getSession();
Session session = em.unwrap(Session.class);
SessionFactory sessionFactory = session.getSessionFactory();
Statistics statistics = sessionFactory.getStatistics();
return statistics.toString();

View File

@@ -14,7 +14,6 @@ import javax.persistence.criteria.Root;
import javax.persistence.metamodel.Attribute;
import org.hibernate.Session;
import org.hibernate.ejb.EntityManagerImpl;
import com.commafeed.backend.model.AbstractModel;
import com.google.common.reflect.TypeToken;
@@ -39,8 +38,7 @@ public abstract class GenericDAO<T extends AbstractModel> {
public void saveOrUpdate(Collection<? extends AbstractModel> models) {
int i = 1;
EntityManagerImpl impl = (EntityManagerImpl) em.getDelegate();
Session session = impl.getSession();
Session session = em.unwrap(Session.class);
for (AbstractModel model : models) {
session.saveOrUpdate(model);