【发布时间】:2013-07-29 12:48:49
【问题描述】:
我需要设置 2 个独立的数据库。一个用于Test类,另一个用于TestTwo类,但我不知道如何配置application.conf文件。
application.conf(第 1 部分):
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/dbone?characterEncoding=UTF-8"
db.dbtwo.driver=com.mysql.jdbc.Driver
db.dbtwo.url="jdbc:mysql://localhost/dbtwo?characterEncoding=UTF-8"
尝试 1 失败:两个类都保存到数据库 1 (dbone):
application.conf(第 2 部分):
ebean.default="*"
ebean.dbtwo="models.TestTwo"
尝试 2 失败:尝试保存内容时出现错误:
[PersistenceException: The type [class models.TestTwo] is not a registered entity? If you don't explicitly list the entity classes to use Ebean will search for them in the classpath. If the entity is in a Jar check the ebean.search.jars property in ebean.properties file or check ServerConfig.addJar().]
application.conf(第 2 部分):
ebean.default="models.Test"
ebean.dbtwo="models.TestTwo"
如何设置以便将 Test 对象保存到 dbone 并将 TestTwo 对象保存到 dbtwo?
编辑:按要求提供 TestTwo 类(没什么特别的;我没有手动分配 Ebean 服务器,除了在 application.conf 文件中):
package models;
import javax.persistence.*;
import play.db.ebean.*;
import play.data.validation.Constraints.Required;
@Entity
public class TestTwo extends Model{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long id;
@Required
public String testString;
public static Model.Finder<Long, TestTwo> find = new Model.Finder<Long, TestTwo>(Long.class, TestTwo.class);
public static TestTwo create (String testString){
TestTwo test = new TestTwo();
test.testString = testString;
test.save();
return test;
}
}
【问题讨论】:
-
请显示更多代码,尤其是用于保存实体的代码。
-
配置看起来不错,可能是您的代码中的某些内容。我不完全确定您是否可以为每个类指定数据库,我只将它用于包。你可能想试试这个。
标签: java mysql playframework ebean