forked from Archives/Athou_commafeed
portable way to unwrap the session (#266)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user