public final class String extends Object
implements Serializable, Comparable<String>, CharSequence
Precompiled in the context of a PreparedStatement means that the SQL statement is compiled by the database server before it is executed. This process involves parsing the SQL statement, checking it for syntax errors, and generating an execution plan that the database can use to efficiently execute the statement. When you create a PreparedStatement in Java, you provide the SQL statement as a parameter to the PreparedStatement constructor. The database server then compiles the SQL statement and stores it in memory so that it can be executed efficiently in the future. Because the SQL statement is precompiled, it can be executed more quickly than a regular Statement, which needs to be compiled every time it is executed. Additionally, since the database server has already checked the syntax of the SQL statement, there is less chance of encountering syntax errors at runtime. Overall, using a PreparedStatement can lead to better performance and more reliable code compared to using a regular Statement in Java.
Employee employee1 = session.load(Employee.class,20); //Step-1
System.out.println(employee1.getEmployeeId(); //Step-2 --o/p=20
system.out.println(employee1.getEmployeeName(); //Step-3 -->O/P:ObjectNotFoundException
If you use load in step-1 hibernate won't fire any select query to fetch employee record from DB at this moment, now at this pint hibernate gives a dummy object ( Proxy ).
This dummy object doesn't contain anything, it is new Employee(20) and you can verify this in step-2 it will print 20 but in step-3 we are trying to find employee information so at this time hibernate fires a sql query to fetch Employee object.
If it is not found in DB then it throws ObjectNotFoundException.
Employee employee2 = session.get(Employee.class,20); //Step-4
For session.get() hibernate fires a sql query to fetch the data from db. so in our case id=20 not exists in DB. so it will return null
@SpringBootApplication
annotation should be in the main of the app and the class could be named something like XXXXXApplication. @Min(value = 18, message = "Age should not be less than 18") Add below dependency- hibernate-validator is entirely separate from the persistence aspects of Hibernate. So, by adding it as a dependency, we're not adding these persistence aspects into the project. <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> <version>6.0.13.Final</version> </dependency> @Max(value = 150, message = "Age should not be greater than 150") private int age; @Email(message = "Email should be valid") private String email; Some other validator- @NotNull validates that the annotated property value is not null. @AssertTrue validates that the annotated property value is true. @Size validates that the annotated property value has a size between the attributes min and max; can be applied to String, Collection, Map, and array properties. @Min validates that the annotated property has a value no smaller than the value attribute. @Max validates that the annotated property has a value no larger than the value attribute. @Email validates that the annotated property is a valid email address. For Bean-When Spring finds an argument annotated with @Valid, it automatically validates the argument and throws an exception if the validation fails. @PostMapping("/register") public ResponseEntity<User> registerUser(@Valid @RequestBody RegisterUserDto registerUserDto) { User createdUser = userService.create(registerUserDto.toUser()); return new ResponseEntity<>(createdUser, HttpStatus.CREATED); } @Data public class RegisterUserDto { @NotEmpty(message = "The full name is required.") @Size(min = 2, max = 100, message = "The length of full name must be between 2 and 100 characters.") private String fullName; @NotEmpty(message = "The email address is required.") @Email(message = "The email address is invalid.", flags = { Flag.CASE_INSENSITIVE }) private String email; }