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/










share|improve this question

























    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/










    share|improve this question























      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/










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 21:05









      Navjot Singh

      166




      166






















          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";






          share|improve this answer




















          • Satisfying answer.
            – Navjot Singh
            Nov 9 at 21:20

















          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






          share|improve this answer



























            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






            share|improve this answer






















            • 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










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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

























            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";






            share|improve this answer




















            • Satisfying answer.
              – Navjot Singh
              Nov 9 at 21:20














            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";






            share|improve this answer




















            • Satisfying answer.
              – Navjot Singh
              Nov 9 at 21:20












            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";






            share|improve this answer












            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";







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 9 at 21:16









            tsolakp

            4,45611219




            4,45611219











            • 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




            Satisfying answer.
            – Navjot Singh
            Nov 9 at 21:20












            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






            share|improve this answer
























              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






              share|improve this answer






















                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






                share|improve this answer












                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 21:19









                Estorskiy

                17112




                17112




















                    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






                    share|improve this answer






















                    • 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














                    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






                    share|improve this answer






















                    • 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












                    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






                    share|improve this answer














                    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







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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? 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
















                    • 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















                    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

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20