I'm trying to connect to multiple databases in Play 2.0. Here's how 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 here's how the 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>
The connections are being properly initialized and I can correctly execute SELECT queries. However, any inserts OR updates do not seem to be working on the "scg2_shard1" connection (everything works on the "default" connection). Any pointers as to what im doing wrong and where should I start looking for to rectify this problem?
add this line to your application.conf
jpa.scg2_shard1=shardPersistenceUnit_1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With