Logo InterviewVault

Welcome back, Sujit Kumar Mishra

SKM

Revision Mode

Document technical questions and best-practice answers.

Cancel

What are the ORM frameworks which you have worked on till now? 

I have worked with two ORM frameworks: Hibernate and JPA.


Hibernate:

Hibernate is a popular ORM framework for Java. It lets us map Java classes to database tables and manage data easily.

Entity Example

@Entity
public class Employee {
    @Id
    private int id;
    private String name;
}

Java Configuration Example

Configuration cfg = new Configuration();
cfg.configure(); // or skip if not using XML
cfg.addAnnotatedClass(Employee.class);
cfg.setProperty("hibernate.connection.url", 
                          "jdbc:mysql://localhost:3306/testdb");
cfg.setProperty("hibernate.connection.username", "root");
cfg.setProperty("hibernate.connection.password", "password");
cfg.setProperty("hibernate.dialect", 
                          "org.hibernate.dialect.MySQLDialect");

//SessionFactory configuration
SessionFactory sessionFactory = 
                      cfg.buildSessionFactory();


JPA (Java Persistence API):

JPA is a standard specification for ORM in Java. Hibernate implements JPA. With JPA, we use annotations to define how Java objects relate to database tables.

Entity Example

@Entity
public class Employee {
    @Id
    private int id;
    private String name;
}

Java Configuration Example

Map<String, Object> props = new HashMap<>();
props.put("javax.persistence.jdbc.url", 
                          "jdbc:mysql://localhost:3306/testdb");
props.put("javax.persistence.jdbc.user", "root");
props.put("javax.persistence.jdbc.password", "password");
props.put("javax.persistence.jdbc.driver", 
                          "com.mysql.cj.jdbc.Driver");

//EntityManagerFactory configuration
EntityManagerFactory emf = 
         Persistence.createEntityManagerFactory("myUnit", props);


Summary:

1: Hibernate and JPA help me work with databases using Java objects, making data operations simpler and avoiding complex SQL queries.

2: Hibernate and JPA allow me to map Java classes to database tables. I use Java-based configuration to set up connections and manage entities, making data access simple and efficient.

Ready for commit