microservices Sixth springboot Configuring Oracle data sources via SPRING-DATA-JPA (SPRING-DATA-JPA details)

Source: Internet
Author: User
Tags iterable

The Jpa:java persistence API is a Java persistence specification. It provides Java developers with an object/mapping tool to manage relational data in Java applications. The goal is to simplify persistent development efforts and integrate ORM technology.

Spring Data JPA is a set of JPA application frameworks encapsulated on the basis of the ORM framework and JPA specifications of spring. Enables developers to access and manipulate data with minimalist code.

Spring Data JPA generates some basic additions and deletions by default.

    List<t> findAll ();    List<t> findAll (Sort var1);    List<t> findAll (iterable<id> var1);    <s extends t> list<s> Save (iterable<s> var1);    void Flush ();    <s extends t> s Saveandflush (S var1);    void Deleteinbatch (iterable<t> var1);    void Deleteallinbatch ();    T GetOne (ID var1);    <s extends t> list<s> findAll (example<s> var1);    <s extends t> list<s> findAll (example<s> var1, Sort var2);

  

Custom Actions:

Specific keywords, using methods and production into SQL are shown in the following table

Keyword Sample JPQL Snippet
and Findbylastnameandfirstname ... where x.lastname =? 1 and x.firstname =? 2
Or Findbylastnameorfirstname ... where x.lastname =? 1 or x.firstname =? 2
Is,equals Findbyfirstnameis,findbyfirstnameequals ... where x.firstname =? 1
Between Findbystartdatebetween ... where x.startdate between? 1 and? 2
LessThan Findbyagelessthan .. where X.age <? 1
Lessthanequal Findbyagelessthanequal ... where x.age?? 1
GreaterThan Findbyagegreaterthan .. where X.age >? 1
Greaterthanequal Findbyagegreaterthanequal ... where x.age >=? 1
After Findbystartdateafter .. where X.startdate >? 1
Before Findbystartdatebefore .. where X.startdate <? 1
IsNull Findbyageisnull ... where x.age is null
Isnotnull,notnull Findbyage (IS) notnull ... where x.age not null
Like Findbyfirstnamelike ... where x.firstname like? 1
Notlike Findbyfirstnamenotlike ... where x.firstname not? 1
Startingwith Findbyfirstnamestartingwith ... where x.firstname like? 1 (parameter bound with appended%)
Endingwith Findbyfirstnameendingwith ... where x.firstname like? 1 (parameter bound with prepended%)
Containing Findbyfirstnamecontaining ... where x.firstname like? 1 (parameter bound wrapped in%)
By Findbyageorderbylastnamedesc ... where x.age =? 1 ORDER BY X.lastname DESC
Not Findbylastnamenot .. where X.lastname <>? 1
Inch Findbyagein (Collection Ages) ... where x.age in? 1
Notin Findbyagenotin (Collection Age) ... where x.age not in? 1
TRUE Findbyactivetrue () ... where x.active = True
FALSE Findbyactivefalse () ... where x.active = False
IgnoreCase Findbyfirstnameignorecase ... where UPPER (x.firstame) = UPPER (? 1)

Custom SQL queries

In fact, the majority of the SQL in spring data can be implemented according to the method name definition, but for some reason we want to use a custom SQL to query, spring data is also the perfect support, the SQL query method above the use of @query annotations, If the deletion and modification are involved in the need to add @modifying. Can also be added as needed @Transactional support for things, query time-out settings, etc.

@Modifying @query ("Update User u set u.username =? 1 where u.id =? 2") int Modifybyidanduserid (String  userName, Long ID) ; @Transactional @modifying@query ("Delete from User where id =? 1") void Deletebyuserid (Long id);  @Transactional (timeout = ten) @Query ("Select u from user u where u.emailaddress =? 1")    User findbyemailaddress (String em ailaddress);

  

microservices Sixth springboot Configuring Oracle data sources via SPRING-DATA-JPA (SPRING-DATA-JPA details)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.