Spring Roo
  1. Spring Roo
  2. ROO-1243

Enable support for two or more databases

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 1.1.0.M2
    • Fix Version/s: 1.1.1.RELEASE
    • Component/s: PERSISTENCE
    • Labels:
      None
    • Environment:
      Any

      Description

      Roo does not support the definition of the Peresistence Unit to be used for an Entity. Although, you can override this from the ITD file by using the @Persistence annotation on the Entity file, but then the @Transactional annotation does not carry the transaction manager required for the entity to be used in a JPA transaction.

        Issue Links

          Activity

          Hide
          Alan Stewart added a comment -

          Support to specify the persistence unit name was recently added in ROO-510. Is this issue still relevant now?
          Thanks

          Show
          Alan Stewart added a comment - Support to specify the persistence unit name was recently added in ROO-510 . Is this issue still relevant now? Thanks
          Hide
          Wendy Cameron added a comment -

          Well yes ROO-510 does solve the problem of specifying the correct persistence unit for each entity.
          However I dont see a property for specifying the required transaction manager. When you autowire EntityManager it will be associated with the transaction manager associated with your entityManagerFactory. So unless you have something like:

          @RooEntity(identifierField = "id", identifierColumn = "PROPERTY_ID", persistenceUnit="gis", transactionManager="gisTransactionManager")
          You potentially will get a transaction manager associated with the wrong entity manager.
          And will get an exception like
          org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress

          Show
          Wendy Cameron added a comment - Well yes ROO-510 does solve the problem of specifying the correct persistence unit for each entity. However I dont see a property for specifying the required transaction manager. When you autowire EntityManager it will be associated with the transaction manager associated with your entityManagerFactory. So unless you have something like: @RooEntity(identifierField = "id", identifierColumn = "PROPERTY_ID", persistenceUnit="gis", transactionManager="gisTransactionManager") You potentially will get a transaction manager associated with the wrong entity manager. And will get an exception like org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
          Hide
          Wendy Cameron added a comment -

          The way i see it you have several options here:

          1) Turn off annotational support for transactions and specify the classes to be used for each transaction manager. Using aop and tx declarative transaction definition. (If it is difficult to segrated classes into groups using different transaction managers this could be nightmarish configuration)

          2) Just use the persistenceUnit="gis" and duplicated gis into each transactional annotation so @Transactional("gis") and add a qualifier element to your transactionManager <qualifier value="gis" /> to pick up this transaction manager for these entities.

          3) Add an additional configuration parameter transactionManager="gisTransactionManager" which references the correct transaction manager by name.

          Personally I quite like option 2.

          Show
          Wendy Cameron added a comment - The way i see it you have several options here: 1) Turn off annotational support for transactions and specify the classes to be used for each transaction manager. Using aop and tx declarative transaction definition. (If it is difficult to segrated classes into groups using different transaction managers this could be nightmarish configuration) 2) Just use the persistenceUnit="gis" and duplicated gis into each transactional annotation so @Transactional("gis") and add a qualifier element to your transactionManager <qualifier value="gis" /> to pick up this transaction manager for these entities. 3) Add an additional configuration parameter transactionManager="gisTransactionManager" which references the correct transaction manager by name. Personally I quite like option 2.
          Hide
          Alan Stewart added a comment -

          Code changed as per option 2) in Git ID 546f62120d1551813cb164c2974be5a97dfa71e6. Note that the --persistenceUnit option must be specified on both the persistence setup and entity commands for this to work correctly and consistently, ie, I can't pick up (without a lot of code hacking) the same value for this option from the persistence setup command and flow through for each entity command. I will be refactoring this code as part of ROO-1463 and plan to re-visit this again.

          Show
          Alan Stewart added a comment - Code changed as per option 2) in Git ID 546f62120d1551813cb164c2974be5a97dfa71e6. Note that the --persistenceUnit option must be specified on both the persistence setup and entity commands for this to work correctly and consistently, ie, I can't pick up (without a lot of code hacking) the same value for this option from the persistence setup command and flow through for each entity command. I will be refactoring this code as part of ROO-1463 and plan to re-visit this again.

            People

            • Assignee:
              Alan Stewart
              Reporter:
              Alberto Yanez
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: