Results 1 to 8 of 8

Thread: Spring Roo with Multiple Databases

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    7

    Default Spring Roo with Multiple Databases

    I'm having a problem trying to figure out how to use multiple databases in the same Roo project. In this case, I need multiple entities mapped to database tables, however the tables will not be placed on the same database.

    There are no relationships between tables on different databases, so all I need is a way to choose a different database for specific entities. Any idea on how to achieve this?

  2. #2
    Join Date
    Jan 2010
    Location
    Mislata - Valencia - Spain
    Posts
    162

    Default

    Quote Originally Posted by petersaints View Post
    I need is a way to choose a different database for specific entities.
    You need more than one persistence units.
    When you create an entity you can choose it with the "--persistenceUnit" parameter.
    See documentation about it.

    Regards !
    Mario Martínez Sánchez
    Project Manager & Software Architect
    --------------------------
    Disid Technologies S.L.
    http://www.disid.com
    --------------------------
    gvNIX
    http://gvnix.googlecode.com
    http://www.gvnix.org

  3. #3
    Join Date
    Jun 2010
    Posts
    440

    Default

    Hi,

    I post this solution about it a while ago...

    I believe this is what you are looking for.
    http://viralpatel.net/blogs/spring-r...configuration/

    I hope it helps you

    Best Roogards
    jD

  4. #4
    Join Date
    Jun 2010
    Posts
    440

    Default

    Hi

    Newer -and cleaner-version on same solution at http://pragmatikroo.blogspot.com/201...databases.html

    Again I hope it helps you

    Best Roogards
    jD

  5. #5
    Join Date
    Dec 2012
    Posts
    2

    Default

    Additional quetsion :
    how about some one want to work "DbOne" with MYSQL, and want "DbTwo: to work with Mongodb ?

  6. #6
    Join Date
    Jun 2010
    Posts
    440

    Default

    @LIBO SU

    That is an interesting solution to work on...
    I don't have it right now but it is totally doable with Spring Data for sure.

    In the meantime I invite you to visit my showcases on Mongo and Roo at http://pragmatikroo.blogspot.com/201...ves-using.html

    B. Roogards
    jD

  7. #7
    Join Date
    Jan 2010
    Location
    Mislata - Valencia - Spain
    Posts
    162

    Default

    Quote Originally Posted by LIBO SU View Post
    how about some one want to work "DbOne" with MYSQL, and want "DbTwo: to work with Mongodb ?
    Yeah, it is possible.
    You need two persistence units, one configured with MYSQL and the other one with Mongodb.
    Then create an entity and choose it with the "--persistenceUnit" parameter.
    Mario Martínez Sánchez
    Project Manager & Software Architect
    --------------------------
    Disid Technologies S.L.
    http://www.disid.com
    --------------------------
    gvNIX
    http://gvnix.googlecode.com
    http://www.gvnix.org

  8. #8
    Join Date
    Nov 2012
    Posts
    7

    Default

    Thanks this mostly works. The only problem I have now is that I wish I could have a default persistenceUnit. Now I have to add an annotation to every class I have so far so that it knows which database to use. Isn't it possible to define one of them as the default and only choose a different one as needed?

    EDIT:
    Another problem is that on application startup the tables get created on both databases. That's undesirable. How to stop it?

    EDIT2:
    Well... I seem to have to define each class manually on persistence.xml. This is boring!! Can't this be automated? Or at least can't I specify that all Entity classes in a given package use a specific persistenceUnit?

    Example:
    <class>pt.unl.fct.p2muca.domain.security.User</class>
    <class>pt.unl.fct.p2muca.domain.security.Gender</class>
    <class>pt.unl.fct.p2muca.domain.security.RoleGroup </class>
    <class>pt.unl.fct.p2muca.domain.security.UserRoleG roup</class>
    <class>pt.unl.fct.p2muca.domain.security.UserActiv ation</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    Having to add this manually is boring!! There is no better solution?
    Last edited by petersaints; Feb 20th, 2013 at 11:27 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •