2011-12-11 47 views
0

DB配置:@PersistenceUnit在PlayFramework中不起作用?

db=mysql://[email protected]/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。 (它必須是'Value#2',因爲它在db2中)。 當然,我已經指定@PersistenceUnit(name =「other」)。 但這沒有任何效果。即使我將pers.unit 的名稱更改爲隨機,也沒有任何錯誤。 這個註釋不起作用或者只是被忽略? 或者我錯了某處? :/

p.s 此外,我試圖獲得EntityManager,因爲它顯示在框架手冊 (/ documentation/jpa#multiple)中。

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

但是這是不可能的: < <的方法getJPAConfig(字符串)是未定義的類型JPA >>

回答

0

播放1.2.3不支持多個數據庫。 多個數據庫部分的支持包含在本文檔頁面中,由 錯誤(該功能僅在github上的主分支中)。

(找不到現在的源)

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

+0

真的嗎?哦..很可惜。 該文檔混淆了一個過載,但無論如何謝謝。順便說一句, – VirtualVoid

+0

!我如何查看文檔?/@文檔/在2.0中不起作用 – VirtualVoid

+0

不確定你的意思。但2.0版本還沒有完全發佈。 – sdespolit

相關問題