title: multi-module project spring 3.0 AnnotationSessionFactoryBean packagesToScan property value to be set module-wise
body: <p>I have the following structure:</p>
  
  <p><strong>common-module</strong></p>
  
  <ul>
  <li>Contains the common module related , services and persistence api</li>
  <li>Contains a common persistence context <strong>test-common-persistence-context.xml</strong>.</li>
  </ul>
  
  <p><strong>search-module (depends on Common Module)</strong></p>
  
  <ul>
  <li>Contains the search module related model beans(marked with JPA Entity annotations), services and persistence api</li>
  <li>Contains search module related spring context files</li>
  </ul>
  
  <p><strong>booking-module (depends on Common Module)</strong>
      - Contains the booking module related model beans(marked with JPA Entity annotations), services and persistence api
      - Contains booking module related spring context files</p>
  
  <p>In the common-module I have <i>test-common-persistence-context.xml</i>.For the <strong>sessionFactory</strong> bean having type
  <i>org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean</i> I need to set the property "packagesToScan" value to the packages in which JPA Entity annotation marked model beans are present.Without it, I get the exception <i>Unknown entity: MY_ENTITY_NAME </i></p>
  
  <p>Common Module: <strong>test-common-persistence-context.xml</strong>    </p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
              &lt;!-- Property Place Holder --&gt;
              &lt;context:property-placeholder location="classpath:test-common-persistence-bundle.properties" /&gt;
  
              &lt;!-- Data Source --&gt;        
              &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
                  &lt;property name="driverClassName" value="${test.db.driverClassName}"/&gt;
                  &lt;property name="url" value="${test.db.jdbc.url}"/&gt;
                  &lt;property name="username" value="${test.db.username}"/&gt;
                  &lt;property name="password" value="${test.db.password}"/&gt;
              &lt;/bean&gt;
  
              &lt;!--
                  Hibernate Configuration
              --&gt; 
              &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" &gt;
                  &lt;property name="dataSource" ref="dataSource"/&gt;
                  &lt;property name="packagesToScan" value="${test.packages.to.scan.jpa.annotations}"/&gt;
                  &lt;property name="hibernateProperties"&gt;
                      &lt;value&gt;
                          &lt;!-- SQL dialect --&gt;
                          hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
                          hibernate.hbm2ddl.auto=update
                      &lt;/value&gt;
                  &lt;/property&gt;      
              &lt;/bean&gt;
  
              &lt;!-- Transaction Manager --&gt;
              &lt;bean id="txManager"  class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
                  &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
              &lt;/bean&gt;
  
              &lt;tx:annotation-driven transaction-manager="txManager"/&gt;
  
      &lt;/beans&gt;
  </code></pre>
  
  <p><i>In my common-module there are no JPA entities so I don't have any package to scan so I keep the "packagesToScan" property value empty</i></p>
  
  <p>However I need to use the same persistence context in my search-module and booking-module tests (<strong>SearchPersistenceTestBase.java</strong>) so that the JPA entities in the respective module gets detected.</p>
  
  <p>Search Module: <strong>SearchPersistenceTestBase.java</strong></p>
  
  <pre><code>    @Ignore
      @ContextConfiguration(locations = {
              "classpath:test-common-persistence-context.xml",
              "classpath:test-search-spring-context.xml"})
      @TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
      public class SearchPersistenceTestBase extends AbstractTransactionalJUnit4SpringContextTests {
  
      }
  </code></pre>
  
  <p>Can anybody please guide me in how to achieve this desired behavior with the set up I have shown above?</p>
  
  <p>** Approach I tried **</p>
  
  <p>I thought of using an additional java.lang.String type bean whose value is set from a properties file  </p>
  
  <pre><code> &lt;bean id="entityPackagesToScan" class="java.lang.String"&gt;
       &lt;constructor-arg value="${test.packages.to.scan.jpa.annotations}" /&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>where <i>test.packages.to.scan.jpa.annotations</i> is defined as empty in <strong>test-common-persistence-bundle.properties</strong> </p>
  
  <p>And then I override the bean definition in <strong>test-search-spring-context.xml</strong> </p>
  
  <p><i>test-search-spring-context.xml</i></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
          &lt;!-- Property Place Holder --&gt;
          &lt;context:property-placeholder location="classpath:test-search-bundle.properties" /&gt;
  
          .. context-component scan elements here
  
          &lt;bean id="entityPackagesToScan" class="java.lang.String"&gt;
              &lt;constructor-arg value="${test.packages.to.scan.jpa.annotations}" /&gt;
          &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>where <i>test.packages.to.scan.jpa.annotations</i> is defined as "com.search.model" in <strong>test-search-bundle.properties</strong> </p>
  
  <p>But this didn't worked and I got the exception <i>Unknown entity: MY_ENTITY_NAME </i></p>
  
  <p>Thanks,<br>
  Jignesh</p>