简体   繁体   中英

What is the runtime for Repository's default "findById" function in Spring Boot?

For simple @PutMapping (see below), does it take the order id and look for the specific order throughout the entire orders table? or does it go to get that specific order directly?

orderRepository is inherited from JpaRepository; database is MySQL

 //Update a order: @PutMapping("/orders/{id}") public Order updateOrder(@PathVariable(value = "id") Long orderId, @Valid @RequestBody Order orderDetails) throws OrderNotFoundException { Order order = orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException(orderId)); order.setMerchant(orderDetails.getMerchant()); order.setStore(orderDetails.getStore()); Order updatedOrder = orderRepository.save(order); return updatedOrder; }

You can see the sql queries that occur by adding the following lines to the properties (application.properties) file:

spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true

findById hibernate query formed in line is as follows:

select order0_.id as id1_0_0_, order0_.name as name2_0_0_ from app_order order0_ where order0_.id=?

The id field is searched as a where condition in the order table. In a WHERE clause, you can specify a search condition (logical expression) that has one or more conditions. All rows for which the predicate in the WHERE clause is True are affected (or returned)

You can read these articles as a suggestion: SQL WHERE clause is here .

Spring Data JPA core concepts is here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM