Hibernate Flashcards

1
Q

What is the hibernate framework?

A

The Hibernate Framework provides object/relational mapping and is concerned with data persistence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the impedance mismatch?

A

Impedance mismatch is the problem presented by persisting Java objects to relational databases.

Java objects are related graphically while RDBMS are tabular.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 5 impedance mismatches?

A

DIGAS

Data Navigation - Walk obj network, DBs are joined toegether to limit queries
Identity - DB sameness, OO == & .equals
Granularity - > classes than tables
Associations - Obj unidirectional, DB foreign key
Subtypes (Inheritance) - RDBMS doesnt have similar concept

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

4 intentions behind Hibernate

A
  1. Domain object model to persist real world processes
  2. Prevent leakage of concerns - logic kept separate from persistence layer
  3. Transparent and Automatic persistence - Java programming to persist objects to a DB (no sql) & through an XML file persistence is provided automatically.
  4. XML meta data - human readable format, automatically maps.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the benefits of using Domain Objects over Data Transfer Objects?

A

Domain objects contain data and logic and so help separate concerns. DTOs only contain data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the steps to achieving persistence in Hibernate?

A
  1. SessionFactory factory;
  2. //Get connection
  3. ManageCourse mc = new ManageCourse()
  4. Integer crs1 = mc.addCourse(“1001”);
  5. public Integer addCourse(int courseID){
  6. Session session = factory.openSession();
  7. Transaction trans = null;
  8. trans = session.beingTransaction();
  9. Course course = new Course(courseID);
  10. session.saveOrUpdate(course);
  11. trans.commit();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the steps to achieving persistence in JDBC?

A
  1. Connection con;
  2. int courseID = c.getCourseID();
  3. String sqlStmt = “INSERT INTO COURSE (course_id)” + VALUES(?)”;
  4. PreparedStatement ps = con.preparedStatement(sqlStmt);
  5. ps.setInt(1, courseID);
  6. ps.execute();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Compare and contrast Persistence with JDBC vs Hibernate

A

Hibernate uses DO instead of DTO.
Hibernate Business layer, JDBC service layer
Hibernate uses SessionFactory, JDBC PreparedStatement
Hibernate’s persistence is transparent and automatic, JDBC’s is SQL written and manual
Hibernate has a cache, JDBC doesnt
Hibernate maps to XML to map POJO, JDBC does this in DAO
Hibernate prevents leakage of concerns, JDBC code is mixed
Hibernate uses saveOrUpdate/ commit, JDBC uses execute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly