Thank you for your reply pgrimard!
I've solved the first mistake.. but not found a solution for org.hibernate.exception.JDBCConnectionException.
Summarizing, I've defined 2 persistence unit in persistence.xml file
Code:
<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/17025" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="password" />
</properties>
</persistence-unit>
<persistence-unit name="persistenceUnitOther" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<!--value='create' to build a new database on each run; value='update' to modify an existing database; value='create-drop' means the same as 'create' but also drops tables when Hibernate closes; value='validate' makes no changes to the database-->
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.connection.url" value="jdbc:sqlserver://remoteHost:3224;databaseName=dbName;user=root;password=password" />
</properties>
</persistence-unit>
So in my application-context I defined a DefaultPersistenceUnitManager and configured it to search configuration in persistence.xml
Code:
<bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath*:META-INF/persistence.xml</value>
</list>
</property>
</bean>
Then I defined my 2 entity manager:
Code:
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="persistenceUnitManager" ref="pum"/>
<property name="persistenceUnitName" value="persistenceUnit" />
</bean>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactoryOther">
<property name="persistenceUnitManager" ref="pum"/>
<property name="persistenceUnitName" value="persistenceUnitOther" />
</bean>
Then i defined the 2 transaction manager:
Code:
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManagerOther">
<property name="entityManagerFactory" ref="entityManagerFactoryOther"/>
</bean>
And at the end I declared:
Code:
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManagerOther" />
If someone have suggestions..