我正在尝试连接到Play 2.0中的多个数据库。这是我的application.conf的样子:
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
这就是persistence.xml的样子
<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>
连接正确初始化,我可以正确执行SELECT查询。但是,任何插入或更新似乎都不起作用于“scg2_shard1”连接(一切都在“默认”连接上工作)。关于我做错了什么以及我应该从哪里开始寻找纠正这个问题的任何指示?
答案 0 :(得分:1)
将此行添加到您的application.conf
jpa.scg2_shard1=shardPersistenceUnit_1