Announcement Announcement Module
Collapse
No announcement yet.
JPAEntityManager reporting that it already has a datasource? How can this be? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPAEntityManager reporting that it already has a datasource? How can this be?

    Hi all,

    I have a BPM application that I am deploying in Alfresco/Activiti 5.5 and it is configured with Spring 3. Both Activiti is configured that way, and I have included my own Spring beans to be wired into Activiti rest app as well. I am trying to have a typical JPA/Hibernate -- managed by Spring configuration I've used in web apps before. I get no errors on startup, but when I try to invoke a Java Service bean from the BPMN model, it uses a service class (which uses a Dao) to get a collection of data. Typical stuff I've done a hundred times in a web app. However, when I try to invoke my service class, I am getting an error stack that looks like I have misconfigured my JPA Entity manager. I also see there is a Hibernate error in the stack, but I am thinking the root cause of my problem is my EM is not configured correctly. I have attached my small project here, along with the errors thrown in the tomcat log file and the configuration files used by my application.

    It seems the real problem here is this part of the stack trace:


    Code:
    Caused by: org.activiti.engine.impl.javax.el.ELException: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@5af1cf78] for key [[email protected]43] bound to thread [http-8080-3]
    Can anyone tell me what this means? Activiti uses a database for keeping track of process variables, which is separate from the database I am trying to connect JPA to. I'm trying to configure my Hibernate sessionFactory using a hibernate config file as such:

    Code:
    <property name="configLocation" value="WEB-INF/classes/hibernate.cfg.xml"/>
    I'm not sure if this is the problem or if I am not giving the correct datasource to JPA? Any help sorting this out would be much appreciated!

    Thanks in advance,

    Griff

  • #2
    Not getting EntityManager..

    After taking a closer look -- it looks like I was not providing a datasource to my JPA entity manager, and that it was using the default datasource that activiti was using for it's process engine.

    I configured a datasource for it and I'm making sure the EMFactory and Transaction manager is using my datasource.

    It then occurred to me that there are 2 JPA EM instances in the spring context, and I was getting the wrong one. So I annotated my AbstractDao class to include the persistence context unit name. Didn't work. I also added the @PersistenceUnit annotation -- that didn't work either. The code is posted below.


    Code:
    	@PersistenceContext(unitName="PSC_PU")
    	@PersistenceUnit(unitName="PSC_PU")
    	public void setEntityManager(EntityManager em) {
    		System.out.println("+++++++++++++++++++++++++++++in setEntityManager +++++++++++++++++");
    		this.em = em;
    	}
    I'm no longer getting the original error, but now the setEntityManager method is never getting invoked.

    New Spring config files attached in file named new-config.zip.

    Any/all replies are appreciated!

    Comment


    • #3
      RESOLVED
      Ok, I had commented out my PersistenceAnnotationBeanPostProcessor bean in trying to narrow down the problem, so that's why the setEntityManager never got called. After adding this back and adding the persistenceUnit attribute to the method call, I finally got the correct persistence unit. I also had to add this to the JPA entity as well. Final step was adding the Entity class to the hibernate.cfg.xml file so that Hibernate knew how to map it. (Since I am using Hibernate as my JPA provider).

      Thanks to anyone who read my messages.

      Comment

      Working...
      X