title: Using two transaction managers and session factories with spring & hibernate annotations
body: <p>I have two transactions managers defined in applicationContext, referencing two completely different sessionFactories. I am attempting to use annotations with one of the transactionmanagers however it seems to be applying all annotations to both transaction managers.</p>
  
  <p>The new db I am migrating to has  <code>&lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;</code> and the other which I am migrating from has  <code>&lt;property name="hbm2ddl.auto"&gt;validate&lt;/property&gt;</code></p>
  
  <p>I have annotated my new domain objects with <code>@Entity</code> hibernate is attempting to validate these classes on the legacy database, which I thought I had set up to ignore annotations (by not specifying annotations). Here are the relevant snippets of appContext:</p>
  
  <pre><code>    &lt;tx:annotation-driven transaction-manager="transactionManager1" /&gt;
      &lt;context:property-placeholder location="file:${catalina.home}/conf/database.properties" ignore-unresolvable="true"/&gt;
  
      &lt;bean id="sessionFactory1" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" p:dataSource-ref="dataSource1" p:configLocation="WEB-INF/classes/hibernate.cfg.xml" p:packagesToScan="com.mycompany"/&gt;
  
  &lt;!-- Declare a datasource that has pooling capabilities--&gt;   
  &lt;bean id="dataSource1" class="com.mchange.v2.c3p0.ComboPooledDataSource" 
  p:driverClass="${app.driverClassName}" p:jdbcUrl="${app.url}" 
  p:user="${app.username}" p:password="${app.password}"
  
      &lt;!-- Declare a transaction manager--&gt;
      &lt;bean id="transactionManager1" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory1" /&gt;
  </code></pre>
  
  <p>and the legacy db in same appContext :</p>
  
  <pre><code>&lt;bean id="sessionFactory2" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"    p:dataSource-ref="dataSource2" p:configLocation="WEB-INF/classes/hibernateTraveller.cfg.xml" p:packagesToScan="com.mycompany"/&gt;
  
  &lt;!-- Declare a datasource that has pooling capabilities--&gt;   
  &lt;bean id="dataSource2" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" 
  p:driverClass="${app2.driverClassName}" p:jdbcUrl="${app2.url}" 
  p:user="${app2.username}" p:password="${app2.password}"
  
  &lt;!-- Declare a transaction manager--&gt;
  &lt;bean id="transactionManager2" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
              p:sessionFactory-ref="sessionFactoryTraveller"&gt; 
  &lt;qualifier value="legacyDB"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>any pointers ?</p>