0
0
Spring Bootframework~20 mins

Database and app orchestration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot Database Orchestration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Spring Boot REST controller method?
Consider this Spring Boot controller method that fetches a user by ID from a database using JPA. What will be the HTTP response status if the user is not found?
Spring Boot
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;

@RestController
@RequestMapping("/users")
public class UserController {

    private final UserRepository userRepository;

    public UserController(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @GetMapping("/{id}")
    public ResponseEntity<User> getUser(@PathVariable Long id) {
        Optional<User> user = userRepository.findById(id);
        if (user.isPresent()) {
            return ResponseEntity.ok(user.get());
        } else {
            return ResponseEntity.notFound().build();
        }
    }
}
AHTTP 200 OK with user data if found, HTTP 404 Not Found if user missing
BHTTP 500 Internal Server Error if user missing
CHTTP 204 No Content if user missing
DHTTP 400 Bad Request if user missing
Attempts:
2 left
💡 Hint
Look at the ResponseEntity methods used for the missing user case.
state_output
intermediate
2:00remaining
What is the value of the transaction status after this Spring Boot service method runs?
Given this service method annotated with @Transactional, what will be the transaction status after the method completes successfully?
Spring Boot
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderService {

    @Transactional
    public void placeOrder(Order order) {
        // save order to database
        // update inventory
        // send confirmation
    }
}
ATransaction is rolled back
BTransaction is left open and active
CTransaction is committed and closed
DTransaction status is unknown
Attempts:
2 left
💡 Hint
What does @Transactional do when no exceptions occur?
🔧 Debug
advanced
2:00remaining
Why does this Spring Boot application fail to connect to the database?
This Spring Boot app throws a connection error at startup. What is the most likely cause?
Spring Boot
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=secret
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
AUsername and password are incorrect
BDriver class name is outdated; should be com.mysql.cj.jdbc.Driver
CDatabase URL is missing the port number
DDatasource URL should start with jdbc:postgresql://
Attempts:
2 left
💡 Hint
Check the driver class name for MySQL Connector/J 8+
📝 Syntax
advanced
2:00remaining
Which option correctly defines a Spring Data JPA repository interface?
You want to create a repository interface for the entity Product with Long as ID type. Which option is syntactically correct?
Apublic interface ProductRepository extends JpaRepository<Product, Long> {}
Bpublic class ProductRepository implements JpaRepository<Product, Long> {}
Cpublic interface ProductRepository extends Repository<Product> {}
Dpublic interface ProductRepository extends JpaRepository<Product> {}
Attempts:
2 left
💡 Hint
JpaRepository requires two generic parameters: entity and ID type.
🧠 Conceptual
expert
3:00remaining
What happens if a Spring Boot @Transactional method calls another @Transactional method in the same class?
Consider a Spring Boot service class where a public @Transactional method calls another public @Transactional method within the same class. What is the behavior of the transaction management in this case?
AAn exception is thrown due to nested @Transactional calls
BBoth methods run in separate transactions
CThe inner method starts a new nested transaction automatically
DThe inner @Transactional method runs without a transaction because Spring proxies are bypassed
Attempts:
2 left
💡 Hint
Think about how Spring AOP proxies work for self-invocation.