Senior
How do you work with databases? Have you had any interesting tasks?
sobes.tech AI
Answer from AI
In working with databases in Java, I usually use ORM frameworks such as Hibernate or JPA, which allow abstraction from specific SQL and work with objects. For simple tasks — JDBC with prepared statements to avoid SQL injections.
Interesting tasks involved optimizing queries and data migrations. For example, I had to implement a complex batch processor to update millions of records with minimal impact on database performance. I used pagination and transactions with isolation control to avoid locks.
An example of a simple query with JPA:
@Entity
public class User {
@Id
private Long id;
private String name;
// getters and setters
}
// In the service
TypedQuery<User> query = entityManager.createQuery("SELECT u FROM User u WHERE u.name = :name", User.class);
query.setParameter("name", "Ivan");
List<User> users = query.getResultList();