Announcement Announcement Module
Collapse
No announcement yet.
Spring Roo with Multiple Databases Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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 !

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment


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

          Comment


          • #6
            @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

            Comment


            • #7
              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.

              Comment


              • #8
                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, 12:27 PM.

                Comment

                Working...
                X