Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play! Framework 2.0 connecting to multiple databases

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?

like image 867
user1439306 Avatar asked Nov 13 '22 04:11

user1439306


1 Answers

add this line to your application.conf

jpa.scg2_shard1=shardPersistenceUnit_1
like image 112
nivash Avatar answered Dec 28 '22 17:12

nivash