0

数据库配置:

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) 未定义 >>

4

1 回答 1

0

Play 1.2.3 不支持多数据库。支持多数据库部分错误地包含在此文档页面中(该功能仅在 github 上的 master 分支中)。

(现在找不到源)

看看例如这里:http ://groups.google.com/group/play-framework/browse_thread/thread/4079cc961db8c750?pli=1

于 2011-12-12T11:41:50.487 回答