Derived methods in spring data jpa
up vote
0
down vote
favorite
Spring Data JPA
documentation tells us that we can have derived methods for delete
functionality. Then the documentation gives example as:
interface UserRepository extends CrudRepository<User, Long>
long deleteByLastname(String lastname);
List<User> removeByLastname(String lastname);
What I found confusing was removeByLastname
. The CrudRepository
has delete
methods which start by delete
word and there is no method which starts with remove
. Do we have methods starting with remove
? If yes, when and how to use them.
Link for the documentation: https://docs.spring.io/spring-data/jpa/docs/2.1.2.RELEASE/reference/html/
java spring orm spring-data-jpa
add a comment |
up vote
0
down vote
favorite
Spring Data JPA
documentation tells us that we can have derived methods for delete
functionality. Then the documentation gives example as:
interface UserRepository extends CrudRepository<User, Long>
long deleteByLastname(String lastname);
List<User> removeByLastname(String lastname);
What I found confusing was removeByLastname
. The CrudRepository
has delete
methods which start by delete
word and there is no method which starts with remove
. Do we have methods starting with remove
? If yes, when and how to use them.
Link for the documentation: https://docs.spring.io/spring-data/jpa/docs/2.1.2.RELEASE/reference/html/
java spring orm spring-data-jpa
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Spring Data JPA
documentation tells us that we can have derived methods for delete
functionality. Then the documentation gives example as:
interface UserRepository extends CrudRepository<User, Long>
long deleteByLastname(String lastname);
List<User> removeByLastname(String lastname);
What I found confusing was removeByLastname
. The CrudRepository
has delete
methods which start by delete
word and there is no method which starts with remove
. Do we have methods starting with remove
? If yes, when and how to use them.
Link for the documentation: https://docs.spring.io/spring-data/jpa/docs/2.1.2.RELEASE/reference/html/
java spring orm spring-data-jpa
Spring Data JPA
documentation tells us that we can have derived methods for delete
functionality. Then the documentation gives example as:
interface UserRepository extends CrudRepository<User, Long>
long deleteByLastname(String lastname);
List<User> removeByLastname(String lastname);
What I found confusing was removeByLastname
. The CrudRepository
has delete
methods which start by delete
word and there is no method which starts with remove
. Do we have methods starting with remove
? If yes, when and how to use them.
Link for the documentation: https://docs.spring.io/spring-data/jpa/docs/2.1.2.RELEASE/reference/html/
java spring orm spring-data-jpa
java spring orm spring-data-jpa
asked Nov 9 at 21:05
Navjot Singh
166
166
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
accepted
They both can be used the same way. You can either name your method to start with remove
or delete
. See PartTree class for DELETE patterns:
private static final String DELETE_PATTERN = "delete|remove";
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
add a comment |
up vote
1
down vote
When generating the repository implementation, Spring Data examines any methods
in the repository interface, parses the method name, and attempts to understand the
method’s purpose in the context of the persisted object. In
essence, Spring Data defines a sort of miniature domain-specific language (DSL)
where persistence details are expressed in repository method signatures.
There is no difference between remove
and delete
. You can use any of them. Same
with find
get
read
add a comment |
up vote
0
down vote
I believe they are using List<User> removeByLastname(String lastname);
because there is already long deleteByLastname(String lastname);
and you can't have a function with the same name and arguments
In modern versions of Spring Data JPA (>=1.7.x) query derivation for delete and remove operations are accessible
https://www.logicbig.com/tutorials/spring-framework/spring-data/jpa-derived-delete-queries.html
But then how is the implementation provided for these two different naming conventions? Isremove
a valid naming convention inSpring Data JPA
?
– Navjot Singh
Nov 9 at 21:16
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
They both can be used the same way. You can either name your method to start with remove
or delete
. See PartTree class for DELETE patterns:
private static final String DELETE_PATTERN = "delete|remove";
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
add a comment |
up vote
1
down vote
accepted
They both can be used the same way. You can either name your method to start with remove
or delete
. See PartTree class for DELETE patterns:
private static final String DELETE_PATTERN = "delete|remove";
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
They both can be used the same way. You can either name your method to start with remove
or delete
. See PartTree class for DELETE patterns:
private static final String DELETE_PATTERN = "delete|remove";
They both can be used the same way. You can either name your method to start with remove
or delete
. See PartTree class for DELETE patterns:
private static final String DELETE_PATTERN = "delete|remove";
answered Nov 9 at 21:16
tsolakp
4,45611219
4,45611219
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
add a comment |
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
Satisfying answer.
– Navjot Singh
Nov 9 at 21:20
add a comment |
up vote
1
down vote
When generating the repository implementation, Spring Data examines any methods
in the repository interface, parses the method name, and attempts to understand the
method’s purpose in the context of the persisted object. In
essence, Spring Data defines a sort of miniature domain-specific language (DSL)
where persistence details are expressed in repository method signatures.
There is no difference between remove
and delete
. You can use any of them. Same
with find
get
read
add a comment |
up vote
1
down vote
When generating the repository implementation, Spring Data examines any methods
in the repository interface, parses the method name, and attempts to understand the
method’s purpose in the context of the persisted object. In
essence, Spring Data defines a sort of miniature domain-specific language (DSL)
where persistence details are expressed in repository method signatures.
There is no difference between remove
and delete
. You can use any of them. Same
with find
get
read
add a comment |
up vote
1
down vote
up vote
1
down vote
When generating the repository implementation, Spring Data examines any methods
in the repository interface, parses the method name, and attempts to understand the
method’s purpose in the context of the persisted object. In
essence, Spring Data defines a sort of miniature domain-specific language (DSL)
where persistence details are expressed in repository method signatures.
There is no difference between remove
and delete
. You can use any of them. Same
with find
get
read
When generating the repository implementation, Spring Data examines any methods
in the repository interface, parses the method name, and attempts to understand the
method’s purpose in the context of the persisted object. In
essence, Spring Data defines a sort of miniature domain-specific language (DSL)
where persistence details are expressed in repository method signatures.
There is no difference between remove
and delete
. You can use any of them. Same
with find
get
read
answered Nov 9 at 21:19
Estorskiy
17112
17112
add a comment |
add a comment |
up vote
0
down vote
I believe they are using List<User> removeByLastname(String lastname);
because there is already long deleteByLastname(String lastname);
and you can't have a function with the same name and arguments
In modern versions of Spring Data JPA (>=1.7.x) query derivation for delete and remove operations are accessible
https://www.logicbig.com/tutorials/spring-framework/spring-data/jpa-derived-delete-queries.html
But then how is the implementation provided for these two different naming conventions? Isremove
a valid naming convention inSpring Data JPA
?
– Navjot Singh
Nov 9 at 21:16
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
add a comment |
up vote
0
down vote
I believe they are using List<User> removeByLastname(String lastname);
because there is already long deleteByLastname(String lastname);
and you can't have a function with the same name and arguments
In modern versions of Spring Data JPA (>=1.7.x) query derivation for delete and remove operations are accessible
https://www.logicbig.com/tutorials/spring-framework/spring-data/jpa-derived-delete-queries.html
But then how is the implementation provided for these two different naming conventions? Isremove
a valid naming convention inSpring Data JPA
?
– Navjot Singh
Nov 9 at 21:16
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
add a comment |
up vote
0
down vote
up vote
0
down vote
I believe they are using List<User> removeByLastname(String lastname);
because there is already long deleteByLastname(String lastname);
and you can't have a function with the same name and arguments
In modern versions of Spring Data JPA (>=1.7.x) query derivation for delete and remove operations are accessible
https://www.logicbig.com/tutorials/spring-framework/spring-data/jpa-derived-delete-queries.html
I believe they are using List<User> removeByLastname(String lastname);
because there is already long deleteByLastname(String lastname);
and you can't have a function with the same name and arguments
In modern versions of Spring Data JPA (>=1.7.x) query derivation for delete and remove operations are accessible
https://www.logicbig.com/tutorials/spring-framework/spring-data/jpa-derived-delete-queries.html
edited Nov 9 at 21:22
answered Nov 9 at 21:13
Justin
37618
37618
But then how is the implementation provided for these two different naming conventions? Isremove
a valid naming convention inSpring Data JPA
?
– Navjot Singh
Nov 9 at 21:16
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
add a comment |
But then how is the implementation provided for these two different naming conventions? Isremove
a valid naming convention inSpring Data JPA
?
– Navjot Singh
Nov 9 at 21:16
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
But then how is the implementation provided for these two different naming conventions? Is
remove
a valid naming convention in Spring Data JPA
?– Navjot Singh
Nov 9 at 21:16
But then how is the implementation provided for these two different naming conventions? Is
remove
a valid naming convention in Spring Data JPA
?– Navjot Singh
Nov 9 at 21:16
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
yes, remove and delete both work in JPA 1.7 and later
– Justin
Nov 9 at 21:21
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233263%2fderived-methods-in-spring-data-jpa%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown