Skip to content

Auto-configure @EnableTransactionManagement with Neo4J #8587

Closed

Description

@mangrish

When using Spring Data Neo4J, any Spring Service or Component that contains a @Transactional annotation will not result in those methods not being registered with the Neo4jTransactionManager. Consequently any group of interactions using a Spring Data Repository that should be bound by a transaction are run individually resulting in unexpected results.

Original SO Question: http://stackoverflow.com/questions/42696967/delete-relationship-with-spring-data-neo4j

Spring Data JIRA Ticket: https://jira.spring.io/browse/DATAGRAPH-971

Sample Project showing error: https://github.com/fichestrati/neo4j-test

Updated version of same project running without Spring Boot:works-without-boot.zip

Affects:

  • Spring Boot 1.5.1 - 1.5.2
  • Spring Data Neo4J 4.2.0-4.2.1
  • Neo4j OGM 2.1.1 - 2.1.2-SNAPSHOT

Activity

  1. changed the title [-]Spring Data Neo4J does not work with `@Transactional` when used with Spring Boot[/-] [+]Spring Data Neo4J (SDN) does not work with @Transactional when used with Spring Boot 1.5.x[/+] on Mar 13, 2017
  2. added
    status: waiting-for-triage
    on Mar 13, 2017
  3. mangrish commented on Mar 13, 2017

    @mangrish
    Author

    ping @wilkinsona: This is kind of a big deal for us. We'd appreciate any expedition you may be able to afford!

  4. added
    type: regression
    and removed
    status: waiting-for-triage
    on Mar 13, 2017
  5. added this to the 1.5.3 milestone on Mar 13, 2017
  6. removed
    type: regression
    on Mar 13, 2017
  7. snicoll commented on Mar 13, 2017

    @snicoll
    Member

    There is no processing of @Transactional because it's not enabled. If you add @EnableTransactionManagement on your sample it works (I understand the b argument in the last output must be null).

    Looking at the code a bit more closely, Spring Boot never set @EnableTransactionManagement with Neo4j. So it looks like transactions with neo4j never worked out of the box. This seems a bit too obvious to me so I am wondering if the spring data neo4j team could chime in and tell me what I am missing.

  8. mangrish commented on Mar 13, 2017

    @mangrish
    Author

    @snicoll That's interesting. TransactionAutoConfiguration must be executed before the Neo4jDataAutoConfiguration which would @EnableTransactionManagement (with the appropriate transaction manager so multiple Spring Data projects that use the AbstractPlatformTransactionManager infrastructure can coordinate). Have I interpreted that incorrectly?

    You are right; it does seem a little too obvious. I'm not sure how this wasn't picked up in previous releases!

  9. snicoll commented on Mar 13, 2017

    @snicoll
    Member

    @mangrish that's not what should happen. TransactionAutoConfiguration is not meant to do what you've just described. As far as I can see it never worked. Let's see what the spring data neo4j team has to say.

  10. mangrish commented on Mar 13, 2017

    @mangrish
    Author

    @snicoll : That's me (the spring data neo4j team).

  11. mangrish commented on Mar 13, 2017

    @mangrish
    Author

    @snicoll: Is the recommendation to always get users to add @EnableTransactionManagement to their applications to make sure transaction management is turned on?

  12. snicoll commented on Mar 13, 2017

    @snicoll
    Member

    @mangrish the way the issue was reported sounded like a regression and I haven't seen anything anywhere that contradicts this. It isn't a regression, it never worked out of the box. We do our best to work with the team working on the underlying technology and we've done some changes in the Neo4J auto-configuration following your recommandation.

    So, no, we do not recommend this. That would be inconsistent with what we do for the JPA support for instance. So we'll need to auto-configure this. I am not keen to backport that to 1.4.x though.

  13. added
    type: enhancement
    on Mar 13, 2017
  14. changed the title [-]Spring Data Neo4J (SDN) does not work with @Transactional when used with Spring Boot 1.5.x[/-] [+]Auto-configure `@EnableTransactionManagement` with Neo4J[/+] on Mar 13, 2017
  15. mangrish commented on Mar 13, 2017

    @mangrish
    Author

    @snicoll: Got it. Thanks for your help! I'm ok with the non backporting to 1.4.x.

  16. self-assigned this
    on Apr 3, 2017
  17. snicoll commented on Apr 3, 2017

    @snicoll
    Member

    Woops, looks like I tried to fix that in #7773 but missed the bits we're discussing here.

  18. added a commit that references this issue on Apr 3, 2017
    0163731
  19. snicoll commented on Apr 3, 2017

    @snicoll
    Member

    I've ran the sample with 1.5.3.BUILD-SNAPSHOT and that works OOB now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions