Junior — Middle
What tools and approaches do you use for working with databases in your projects?
sobes.tech AI
Answer from AI
For working with databases in Java projects, the following tools and approaches are often used:
- JDBC — a basic API for interacting with relational databases through SQL queries.
- ORM frameworks (Hibernate, JPA) — allow working with the database through objects, simplifying the mapping of tables to classes.
- Spring Data — facilitates the creation of repositories and working with the database, integrating with JPA and other technologies.
- Flyway or Liquibase — for managing database schema migrations.
Example of using Spring Data JPA:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
// getters and setters
}
public interface UserRepository extends JpaRepository<User, Long> {
List<User> findByName(String name);
}
This approach allows writing less code for CRUD operations and focusing on business logic.