无法在Play 2中使用多个ebean数据库 [英] Unable to use multiple ebean databases in Play 2

查看:122
本文介绍了无法在Play 2中使用多个ebean数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Play Framework 2.0.3设置一个稍微复杂的项目。

We are setting up a slightly complicated project using Play Framework 2.0.3.

我们需要访问多个数据库(预先存在)并希望这样做使用框架内置工具(即EBean)。

We need to access several databases (pre-existing) and would like to do it using the frameworks built-in facilities (ie. EBean).

我们尝试在models包中创建所有模型类,然后使用其FQN映射每个类到application.conf中相应的EBean属性:

We tried to create all model classes within the "models" package, and then map each class with its FQN to the corresponding EBean property in the application.conf:

ebean.firstDB="models.ClassA,models.ClassB,models.ClassC"
ebean.secondDB="models.ClassD"
ebean.thirdDB="models.ClassE,models.ClassF"

这似乎不起作用:

PersistenceException: Error with [models.SomeClass] It has not been enhanced but it's superClass [class play.db.ebean.Model] is? (You are not allowed to mix enhancement in a single inheritance hierarchy) marker[play.db.ebean.Model] className[models.SomeClass] 

我们检查并重新检查并且配置正常!

We checked and re-checked and the configuration is OK!

然后我们尝试为每个数据库模型类使用不同的Java包并在application.conf中相应地映射它们:

We then tried to use a different Java package for each database model classes and map them accordingly in the application.conf:

ebean.firstDB = "packageA.*"
ebean.secondDB = "packageB.*"
ebean.thirdDB = "packageC.*"

从数据库中读取信息时很好,但是当您尝试保存/更新对象时,我们得到:

This works fine when reading information from the database, but when you try to save/update objects we get:

PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programatically via registerServer()

任何想法?

谢谢!
Ricardo

Thanks! Ricardo

推荐答案

您必须在查询中指定要访问的数据库。

You have to specify in your query which database you want to access.

例如,如果要从secondDB检索所有用户:

For example, if you want to retrieve all users from your secondDB :

// Get access to your secondDB
EbeanServer secondDB = Ebean.getServer("secondDB");

// Get all users in secondDB
List<User> userList = secondDB.find(User.class).findList(); 

这篇关于无法在Play 2中使用多个ebean数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆