Shared Flashcard Set

Details

Hibernate Interview
n/a
27
Computer Science
Graduate
05/13/2013

Additional Computer Science Flashcards

 


 

Cards

Term

What is ORM?

Definition
ORM is the automated persistence of objects in a Java application to the tables in a relational database.
Term

What does ORM consists of?

(Hint: 4)

Definition

a. API for performing basic CRUD operations.

b. API to express queries referring to classes.

c. Facilities to specify metadata.

d. Optimization facilities: dirty checking, lazy associations, fetching.

Term

What is Hibernate?

Definition
Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map Java objects (POJO) to relational database tables using (XML) configuration files.
Term

Why do you need ORM tools like hibernate?

Definition

It shields developers from messy SQL by improving productivity, performance, maintainability, and portability.

Term

What does Hibernate simplify?

(Hint: 5)

Definition

- Saves and retrieves domain objects.

- Makes database columns and table name changes.

- Centralizes pre-save and post-retrieve logic.

- Complex joins for retrieving related items.

- Schema creation from object model.

Term

What is the need for the Hibernate xml mapping file?

Definition
It tells Hibernate which tables and columns to use to load and store objects.
Term

What are the important tags of hibernate.cfg.xml?

(Hint: 4)

Definition

<hibernate-configuration>, <session-factory>, <property>, <mapping resource>

hibernate-configuration, session-factory, property, mapping resource

Term

What role does the Session interface play in Hibernate?

Definition

It is to create a single-threaded object that represents a conversation between the application and the persistent storage.

Term

What role does the SessionFactory interface play in Hibernate?

Definition
The SessionFactory caches generates SQL statements (and other mapping metadata) that Hibernate uses at runtime.
Term

What is the general flow of Hibernate communication with RDBMS?

(Hint: 5)

Definition

- Load the hibernate.cfg.xml file and a create configuration object.

- Create session factory from configuration object.

- Get one session from this sessionFactory.

- Create HQL query.

- Execute query to get list containing Java objects.

Term

What is Hibernate Query Language (HQL)?

Definition
A Hibernate specific query language that embodies a powerful and flexible way to query, store, update, and retrieve objects from a database.
Term

How do you map Java objects with Database tables with Hibernate-Mapping?

(Hint: 2)

Definition

- First you need to write Java domain objects (beans with setters and getters).

- Write hbm.xml, where we map java class to table and database columns to Java class variables.

Term

What's the difference between load() and get()?

Definition

- Load() is only good if the object exists, and will throw an exception if it doesn't. It also returns a proxy by default, and the database won't be hit until the proxy is invoked.

- Get() will return null if the object doesn't exists, and will hit the database immediately.

Term

How do you define a sequence generated primary key in hibernate?

Definition
Use the <generator> tag.
Term

How do you invoke Stored Procedures in Hibernate?

Definition
Stored procedures are defined in the mapping xml document and called whenever required.
Term

Explain Criteria API.

Definition
A simplified API for retrieving entities by composing Criterion objects.
Term

How do you switch between different relational databases in Hibernate?

(Hint: 3)

Definition

- In hibernate.cfg.xml change the driver properties (URL, username, and password).

-In hibernate.cfg.xml change the property tag (dialect).

- Use appropriate connector jar.

 

Term

If you want to see the Hibernate generated SQL statements on console, what should you do?

Definition

In hibernate configuration file set as follows:

<property name=”show_sql”>true</property>

Term

What are some advantages of Hibernate over JDBC?

(Hint: 7)

Definition

With Hibernate....

1. ORM takes care of the mapping to database tables.

2. Provides transparent persistence while interacting with the RDBMS.

3. Provides a powerful query language.

4. Handles mapping of table data to application objects by itself.

5. Maintains object-table mapping.

6. The cache is set to application work space.

7. Enables developers to define a version type field.

Term

What are the Collection types in Hibernate?

(Hint: 5)

Definition
Bag, Set, List, Array, Map.
Term

What do you mean by fetching strategy in Hibernate?

Definition
It is a strategy Hibernate uses for retrieving associated objects if the application needs to navigate the association.
Term

What are Callback interfaces?

Definition
A interfaces that allows a application to receive a notification when something interesting happens to an object (like loaded, saved, deleted).
Term

What are the types of Hibernate instance states?

(Hint: 3)

Definition

Transient – not associated with any data. After instantiation.

Persistent – associated with data. After CRUD method (save, update, delete).

Detached – no longer associated with the data. After session is closed.

 

 

Term

What are the types of inheritance models in Hibernate?

(Hint: 3)

Definition
Table per class hierarchy, Table per subclass, Table per concrete class.
Term

Spell out each role of of the Session Interface in Hibernate.

(Hint: 3)

Definition

- Wrap a JDBC connection.

- Factory to Transaction

- Holds a mandatory (first-level) cache of persistent objects.

 

Term
What can you use the Hibernate interfaces for?
Definition
Storing and retrieving persistent objects and controlling transactions.
Term

What are some major Annotations in Hibernate?

(Hint: 4)

Definition
@Entity, @Table, @Id, @GeneratedValue
Supporting users have an ad free experience!