Tag: entitymanager

JPA,实体管理器,选择许多列并获取结果列表自定义对象

如何获取自定义对象列表,如查询下面的结果: SELECT p.category.id, count(p.id) FROM Product p left join p.category c WHERE p.seller.id=:id GROUP BY c.id 例如: return getEntityManager().createQuery(“SELECT p.category.id, count(p.id) FROM Product p left join p.category c WHERE p.seller.id=:id GROUP BY c.id”).setParameter(“id”, id).getResultList(); 我需要一张类别ID和类别中的产品数量的地图。

Heroku / Play / BoneCp连接问题

我在heroku上有一个使用游戏的应用程序。 它工作时间最长,但最近我开始得到这个: Caused by: java.sql.SQLException: Timed out waiting for a free available connection. at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169) ~[hibernate-core-4.1.9.Final.jar:4.1.9.Final] at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:503) ~[bonecp-0.7.1.RELEASE.jar:0.7.1.RELEASE] 这是由 org.postgresql.util.PSQLException: FATAL: too many connections for role “ejmatdbwywaugk” 现在这显然是一个连接泄漏,除了我正在使用JPA.em()。 Play示例永远不会关闭像这样获得的实体管理器。 我尝试关闭它,但随后应用程序爆炸说实体经理已经关闭。 有任何想法吗?

在EntityManager查询上设置超时

我目前正从EntityManager查询中获取连接超时错误。 是否可以为这些设置超时? persistence.xml中 org.eclipse.persistence.jpa.PersistenceProvider call.structure.Task call.structure.Installation call.structure.Contents call.structure.Recipient call.structure.CallTask call.structure.SmsTask call.structure.EmailTask call.security.User call.structure.content.Content call.structure.content.RecordContent call.structure.content.WaitContent call.structure.content.TextContent call.structure.content.VariableContent call.structure.content.SoundContent call.structure.content.SubjectContent call.structure.content.FileContent call.structure.Bounce 代码在我的线程的run函数中超时: private class TaskDB extends Thread { private final long WAITING_TIME = 20000L; @Override public void run() { Set remove = SMSManager.this.getRemoveTask(); Set normal = SMSManager.this.getNormalTask(); try { while(true){ EntityManager em = DB.getEM(); //Calls […]

修复Spring MVC应用程序中的Null EntityManger?

在下面的代码中,我注入了EnitityManager,它总是显示为null ; public class GenericController extends AbstractController { @PersistenceContext(unitName = “GenericPU”) private EntityManager em; protected ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { //(em == null) is always trigged if (em == null) throw new NullPointerException(“em is null”); Collection Generics = em.createNamedQuery(“Generic.findAll”).getResultList(); ModelAndView mav = new ModelAndView(“Generic”); mav.addObject(Generics); return mav; } } 这是bean定义,在dispatcher-servlet.xml中定义。 应该在persistence-context.xml文件中定义基于tx:annotation的注入EnitityManager。 […]

JAVA:multithreading环境中的EntityManager对象

如果我有多个线程,每个使用注入器来获取EntityManager对象,每个使用em对象来选择其他类对象的列表。 准备用于for循环。 如果一个线程先完成并调用clear(),那会影响其他线程吗? 喜欢for循环会有exception吗? close()怎么样? 如果答案是“它取决于”,那么(类定义?方法调用?)和where(java code?annotation?xml?)应该看看它是如何依赖的? 我没有写源,我只是在没有文档的情况下使用别人的库。 谢谢。

应该何时创建/打开EntityManagerFactory实例?

好的,我阅读了一些文章/示例如何在单例中编写实体管理器工厂。 其中一个对我来说最容易理解: http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html 我了解到EntityManagerFactory(EMF)应该只在应用程序范围内创建一次。 并确保在使用后关闭EMF(?) 所以我编写了EMF helper类来使用的业务方法: public class EmProvider { private static final String DB_PU = “KogaAlphaPU”; public static final boolean DEBUG = true; private static final EmProvider singleton = new EmProvider(); private EntityManagerFactory emf; private EmProvider() {} public static EmProvider getInstance() { return singleton; } public EntityManagerFactory getEntityManagerFactory() { if(emf == null) { […]