Play! Framework 2.0 connecting multiple databases

I am trying to connect to several databases in Play 2.0. This is what my application.conf looks like:

db.default.driver= com.mysql.jdbc.Driver db.default.url="jdbc:mysql://localhost:3306/scg2?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&autoreconnect=true" db.default.user=root db.default.jndiName=DefaultDS db.scg2_shard1.driver= com.mysql.jdbc.Driver db.scg2_shard1.url="jdbc:mysql://localhost:3306/scg2_shard1?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&autoreconnect=true" db.scg2_shard1.user=root db.scg2_shard1.jndiName=ShardDS_1 

And this is what persistence.xml looks like

 <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <non-jta-data-source>DefaultDS</non-jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit> <persistence-unit name="shardPersistenceUnit_1" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <non-jta-data-source>ShardDS_1</non-jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.show_sql" value="true"/> </properties> </persistence-unit> 

Connections are correctly initialized, and I can correctly execute SELECT queries. However, any insertion of OR updates does not seem to work on the "scg2_shard1" connection (everything works on the "standard" connection). Any guidance on what I'm doing wrong, and where should I look for a fix for this problem?

+4
source share
1 answer

add this line to your application.conf

 jpa.scg2_shard1=shardPersistenceUnit_1 
+1
source

Source: https://habr.com/ru/post/1416325/


All Articles