@PersistenceUnit在Play Framework中不起作用?

时间:2011-12-11 15:53:21

标签: hibernate jpa playframework persistence-unit

DB配置:

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);

它始终打印值#1。 (它必须是'值#2',因为它在db2中)。 当然,我已经指定了@PersistenceUnit(name =“other”)。 但这没有任何影响。即使我改变了pe​​rs.unit的名字 随机,没有任何错误。 这个注释不起作用或只是被忽略? 或者我在某处弄错了? :/

P.S 此外,我试图获得框架手册中显示的EntityManager (/文档/ JPA#倍数)。

EntityManager em = JPA.getJPAConfig("other").em();

但这不可能: &LT;&LT;对于JPA&gt;&gt;类型,方法getJPAConfig(String)未定义。

1 个答案:

答案 0 :(得分:0)

  

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

(现在找不到来源)

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