数据库配置:
db=mysql://root@localhost/db
jpa.dialect=org.hibernate.dialect.MySQLDialect
....
db_other.url=jdbc:mysql://localhost/db2
db_other.driver=com.mysql.jdbc.Driver
db_other.user=root
db_other.pass=
db_other.jpa.dialect=org.hibernate.dialect.MySQLDialect
在这些数据库中,我有绝对精确的表(克隆)。但不同之处在于这些表中有不同的值。(分别为“价值#1”和“价值#2”)。
一个简单的模型:
package models;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PersistenceUnit;
import javax.persistence.Table;
import play.db.jpa.GenericModel;
@Entity
@PersistenceUnit(name="other")
@Table(name="testtable")
public class DbTest extends GenericModel {
@Id
public String value;
}
其余代码:
List<DbTest> lst = DbTest.findAll();
if(!lst.isEmpty())
System.out.println(lst.get(0).value);
它总是打印 Value #1。(它必须是 db2 中的“值 #2”)。当然,我已经指定了@PersistenceUnit(name="other")。但这没有任何影响。即使我将 pers.unit 的名称更改为随机,也没有任何错误。此注释不起作用或只是被忽略?还是我在某个地方弄错了?:/
ps 另外,我尝试获取框架手册 (/documentation/jpa#multiple) 中显示的 EntityManager。
EntityManager em = JPA.getJPAConfig("other").em();
但这是不可能的:<< JPA 类型的方法 getJPAConfig(String) 未定义 >>