Announcement Announcement Module
Collapse
No announcement yet.
Mongo-only project should not have @Transactional annotation in service layer impl Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mongo-only project should not have @Transactional annotation in service layer impl

    Creating a Spring Roo MongoDb project such as the one shown in the Pizza tutorial will yield a service layer implementation that contains a @Transactional attribute. This is misleading as MongoDb does not support transactions. However, it can actually cause some frustration if you subsequently create a SpringJUnit4ClassRunner-based JUnit test and attempt to call a method on the service. You'll be met with a slew of errors because the JUnit runner will expect a "transactionManager" bean in the application context. This bean won't exist by default and is also not described in the Pizza tutorial.

    The solution is simply to remove the @Transactional attribute, but perhaps it shouldn't be there in the first place?
    I would think the typical user isn't looking to combine MongoDb with transactional resources in the service layer.
    Most likely, it will be MongoDb alone and there won't be interaction with anything else that requires @Transactional.


  • #2
    To get Junit tests to work properly with spring-data, roo and mongoDb, I stripped all the @Roo annotations from my service layer and manage them manually. Also when generating integration tests on Roo mongo entities make sure you have transactional = false, ex.
    ‚Äč
    Code:
    @RooIntegrationTest(entity = MyEntity.class, transactional = false)
    public class MyEntityIntegrationTest ...

    Comment

    Working...
    X