Spring Data: “delete by” is supported?

后端 未结 9 2235
长情又很酷
长情又很酷 2020-11-28 20:57

I am using Spring JPA for database access. I am able to find examples such as findByName and countByName, for which I dont have to write any method implementation. I am hopi

相关标签:
9条回答
  • 2020-11-28 21:41

    Be carefull when you use derived query for batch delete. It isn't what you expect: DeleteExecution

    0 讨论(0)
  • 2020-11-28 21:42

    Yes , deleteBy method is supported To use it you need to annotate method with @Transactional

    0 讨论(0)
  • 2020-11-28 21:44

    If you take a look at the source code of Spring Data JPA, and particularly the PartTreeJpaQuery class, you will see that is tries to instantiate PartTree. Inside that class the following regular expression

    private static final Pattern PREFIX_TEMPLATE = Pattern.compile("^(find|read|get|count|query)(\\p{Lu}.*?)??By")

    should indicate what is allowed and what's not.

    Of course if you try to add such a method you will actually see that is does not work and you get the full stacktrace.

    I should note that I was using looking at version 1.5.0.RELEASE of Spring Data JPA

    0 讨论(0)
提交回复
热议问题