Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use multiple ebean databases in Play 2

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

We need to access several databases (pre-existing) and would like to do it using the frameworks built-in facilities (ie. 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"

This doesn't 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 re-checked and the configuration is OK!

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

Any ideas?

Thanks! Ricardo

like image 272
Ricardo Zuasti Avatar asked Aug 30 '12 16:08

Ricardo Zuasti


1 Answers

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

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(); 
like image 160
aurelien_lepage Avatar answered Oct 11 '22 04:10

aurelien_lepage