Announcement Announcement Module
Collapse
No announcement yet.
ROO: Multiple Session Factory. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ROO: Multiple Session Factory.

    ROO : 1.1.0M1 (Created Two septate ROO Projects)

    Project1: Web Application (Connects to ORACLE for SpringSecurity, other app data) - WAR

    Project2: Stand alone application (Connects to MYSQL for app specific data) - JAR

    Both projects works perfectly fine separately, but facing issues with trying to use (Project2)JAR with in Project1(War).

    -------- tried to make following fix, to overcome overlapping, it worked but seems unstable.

    Project2(Jar)
    1) Renamed: META-INF/spring folder to META-INF/springapp
    Code:
    	<context:property-placeholder location="classpath*:META-INF/springapp/*.properties"/>
    2) Other Changes in applicationConext.xml

    Code:
    	<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="fmDataSource">
            <property name="driverClassName" value="${database.driverClassName}"/>
            <property name="url" value="${database.url}"/>
            <property name="username" value="${database.username}"/>
            <property name="password" value="${database.password}"/>
        </bean>
        <bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
            <property name="entityManagerFactory" ref="fmEntityManagerFactory"/>
        </bean>
        <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
        <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="fmEntityManagerFactory">
        	 <property name="persistenceUnitManager" ref="persistenceUnitManager" />
             <property name="dataSource" ref="fmDataSource"/>
        </bean>
        
        <bean id="persistenceUnitManager" class="com.fox.dv.filemover.CustomPersistenceUnitManager">
    	  <property name="persistenceXmlLocations">
    	    <list>
    	      <value>classpath*:META-INF/springapp/persistence.xml</value>
    	    </list>
    	  </property>
    	  <property name="defaultDataSource" ref="fmDataSource"/>
    	</bean>
    3. Custom Persistence Unit Manager

    Code:
    package com.fox.dv.filemover;
    
    import java.net.URL;
    import java.util.List;
    
    import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager;
    import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo;
    
    public class CustomPersistenceUnitManager extends DefaultPersistenceUnitManager {
    
      protected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
        super.postProcessPersistenceUnitInfo(pui);
        pui.addJarFileUrl(pui.getPersistenceUnitRootUrl());
    
        MutablePersistenceUnitInfo oldPui = (MutablePersistenceUnitInfo) getPersistenceUnitInfo(pui.getPersistenceUnitName());
        if (oldPui != null) {
          List<URL> urls = oldPui.getJarFileUrls();
          for (URL url : urls) {
        	  System.out.println(url.toString());
            pui.addJarFileUrl(url);
          }
        }
      }
    }

    Just wondering, if this approach is right, or there is some other clean way to handle this scenario.
    Last edited by rajatluthra; Jun 2nd, 2010, 12:19 PM.

  • #2
    Some insight: Multiple Session Factory

    Application Container Log Shows following: (Named query not found: job.findAllJobsAndTaskDetails)
    ----------------------------------------------------------------------------------------------------------------------

    1) Oracle Session Factory Initilized Successfully as defined in Project1(WAR)
    2) named query findJobAndTaskDetails called successfully (ORACLE DB Dependent)
    3) MySQL session Factory Initlized Successfully as defined in Project2(JAR) used by Project1(WAR)
    4) Any Call to named query findJobAndTaskDetails after MySQL session Factory initlization is a failure.

    Code:
    SEVERE: >>org.springframework.dao.InvalidDataAccessApiUsageException: Named query not found: job.findAllJobsAndTaskDetails; nested exception is java.lang.IllegalArgumentException: Named query not found: job.findAllJobsAndTaskDetails
    >>java.lang.IllegalArgumentException: Named query not found: job.findAllJobsAndTaskDetails
    >>	at org.hibernate.ejb.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:108)
    >>	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >>	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    >>	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    >>	at java.lang.reflect.Method.invoke(Method.java:597)
    >>	at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
    >>	at $Proxy89.createNamedQuery(Unknown Source)
    >>	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >>	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    >>	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    >>	at java.lang.reflect.Method.invoke(Method.java:597)
    >>	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    >>	at $Proxy92.createNamedQuery(Unknown Source)
    >>	at com.fox.dv.qmanager.domain.Job.findJobAndTaskDetails_aroundBody4(Job.java:113)
    Last edited by rajatluthra; Jun 1st, 2010, 05:42 PM.

    Comment


    • #3
      Some insight: Multiple Session Factory

      Possible Cause:

      1) Roo uses <context:spring-configured/> by default to inject @PersistenceContext into entities.

      As I have multiple persistence-unit (multiple persistence.xml); Seems like I'm missing the steps to tell Entity which persistence-unit it should pick.

      As the logs shows, MySQL is configured after Oracle, seems like both projects have "mysql- persistence-unit".

      #Tried following FIX:

      To fix this issue I re-named the persistence-unit defined in Project1 (WAR) to:
      Code:
      <persistence-unit name="oracle" transaction-type="RESOURCE_LOCAL">
      AND I re-named the persistence-unit defined in Project2 (JAR) to:
      Code:
      <persistence-unit name="mysql" transaction-type="RESOURCE_LOCAL">
      AND UPDATED ALL *_Roo_Entity with (unitName="oracle"):
      Code:
      privileged aspect Job_Roo_Entity {
          
          @PersistenceContext(unitName="oracle")
          transient EntityManager Job.entityManager;
      ...
      Still trying to resolve the issue.
      Last edited by rajatluthra; Jun 1st, 2010, 07:21 PM.

      Comment


      • #4
        Can Roo project handle multiple session factories?

        Is it possible for ROO project to support multiple session factories? If so, what will be the best approach, one should take.

        ** Need to support both ORACLE & MYSQL.

        Comment

        Working...
        X