我正在尝试连接到 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”连接(一切都适用于“默认”连接)。关于我做错了什么以及我应该从哪里开始寻找纠正这个问题的任何指示?