我需要设置 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;
}
}