Java – cannot use multiple ebean databases in play 2

We are using play framework 2.0 3 set up a slightly complex project

We need to access several databases (pre-existing) and want to implement them using the framework's built-in tool (i.e. ebean)

We try to create all model classes in the "models" package, and then map each class with FQN to application Corresponding ebean attribute in conf:

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

This does not seem to work:

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 rechecked that the configuration is normal!

Then, we try to use different Java packages for each database model class, and in application Map them accordingly in conf:

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

This works 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()

Any ideas?

thank you! Ricardo

Solution

You must specify the database to access in the query

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();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>