Multiple Databases with Play Framework 2.1.x

后端 未结 3 459
面向向阳花
面向向阳花 2020-12-28 08:52

I have 2 databases that I need to connect to. I can easily connect to them in the application.conf file like so:

db.default.driver=org.postgresql.Driver
db.d         


        
相关标签:
3条回答
  • 2020-12-28 09:23

    Ok, your application.conf seems to be correct.

    You may use the secondary server like this:

    EbeanServer secondary = Ebean.getServer("secondary");
    secondary.find(User.class).findList();
    

    Once you've got your secondary server, you may treat it just as you treat the Ebean singleton.

    0 讨论(0)
  • 2020-12-28 09:23

    I had the same problem and I fixed it by specifying the server name at the Model.Finder level.

    So in your case, in your User class, you should have something like :

    public static Model.Finder<Long, User> find = new Finder<Long, User>("secondary", Long.class, User.class);
    
    0 讨论(0)
  • 2020-12-28 09:27

    You can use both:

    public static Model.Finder<Long, User> find = new Finder<Long, User>("secondary", Long.class, User.class);
    

    and

    Ebean.getServer("secondary");
    

    But you have to use the save method with the server declaration on your entity

    public void save(String server)
    

    Without save() ebean uses the default server, even on your user-entity!

    0 讨论(0)
提交回复
热议问题