1 Reply Latest reply on Oct 24, 2006 4:46 AM by Yair Zaslavsky

    Using EntityManager from a POJO

    Yair Zaslavsky Newbie

      Hi all,
      I get from time to time an exception that I cannot open a JDBC connection (my connection pool is configured to be of maximum 200 connections, and we're still in a development stage, so I really don't think that we're getting to a stage that all connections run out or something like that).

      This is the exception I get:
      javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:567)
      at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:56)

      I noticed I always get it from a method that is located in a Pojo class that contains an EntityManager field (thus, I can activate the method, which is supposed to obtain some information from the database).
      I pass the EntityManager object to an instance of this class, from a stateless session bean class , where the EntityManager is injected.
      I do not get the exception for methods that are defined in EJBs that inject the entity manager, and unfortunately, the behavior is inconsitent (cant find a scenario that is 100% reproducable, but in all the cases it reproduced it was only at the method of this POJO).
      Can anyone help and tell me if I'm doing wrong that I tried to pass the EntityManager object to a POJO and use it from its context?