• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/46

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

46 Cards in this Set

  • Front
  • Back

What is ORM ?

ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database.
What does ORM consists of ?
* API for performing basic CRUD operations

* API to express quries refering to classes

* Facilities to specify metadata

* Optimization facilities : dirty checking,lazy associations fetching
What is Hibernate?
Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects to relational database tables using (XML) configuration files.Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.
What is the need for Hibernate xml mapping file?
Hibernate mapping file tells Hibernate which tables and columns to use to load and store objects.
What are the most common methods of Hibernate configuration?
* Programmatic configuration
* XML configuration (hibernate.cfg.xml)
What are the important tags of hibernate.cfg.xml?
* JDBC connection configuration
* SQL variant to generate
* Size of connection pool
* Automation generation of schema
* Mapping files
What are the Core interfaces are of Hibernate framework?
* Session interface
* SessionFactory interface
* Configuration interface
* Transaction interface
* Query and Criteria interfaces
What role does the Session interface play in Hibernate?
The Session interface is the primary interface used by Hibernate applications. It is a single-threaded, short-lived object representing a conversation between the application and the persistent store. It allows you to create query objects to retrieve persistent objects.
What role does the SessionFactory interface play in Hibernate?
The application obtains Session instances from a SessionFactory. There is typically a single SessionFactory for the whole application—created during application initialization. The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime. It also holds cached data that has been read in one unit of work and may be reused in a future unit of work.
How do you map Java Objects with Database tables?

First we need to write Java domain objects (beans with setter and getter). The variables should be same as database columns.

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

How do you define sequence generated primary key in hibernate?
Using <generator> tag.
Define HibernateTemplate?

org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.

How do you switch between relational databases without code changes?
Using Hibernate SQL Dialects , we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined.
What are derived properties?
The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.
What is component mapping in Hibernate?

* A component is an object saved as a value, not as a reference
* A component can be saved directly without needing to declare interfaces or identifier properties
* Required to define an empty constructor
* Shared references not supported

What do you mean by fetching strategy ?

A fetching strategy is the strategy Hibernate will use for retrieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the O/R mapping metadata, or over-ridden by a particular HQL or Criteria query.

What is automatic dirty checking?
Automatic dirty checking is a feature that saves us the effort of explicitly asking Hibernate to update the database when we modify the state of an object inside a transaction.
What are the types of inheritance models in Hibernate?

* Table per class hierarchy
* Table per subclass
* Table per concrete class

Why do we need ORM tools like Hibernate?

Less SQL


Improved Productivity


-no sql,


-less code to write


-a high level object oriented api


Improved Performance


-Sophisticated Cashing


-Lazy and Eager Loading


Improve Maintainability


-less code


Improved Portability


-A generic framework, portable to multiple databases based on dialect.

What are the types of Hibernate instance states?

Transient, -not associated with data.


Persistent, -associated with data after a CRUD method


and Detatched - After a session is closed. Not directly associated with data.

What are the essential properties of a transaction?

ACID

What are the Transaction Isolation Levels in Hiberante?

The transaction isolation level indicates the degree to which two transactions interact with each other over the same data. The transaction problems that can occur are dirty read, unrepeatable read, and phantom read.



The isolation levels are


Read Uncommitted


Read Committed


Repeatable Read


Serializable

What is the difference between First Level and Second Level Cache in Hibernate?

First Level


-Default


-Transaction Scoped


-Formed by the Session Object


-Guarantees Object Identity inside a transaction



Second Level Cache


-Optional/Pluggable


-Might be scoped to a process or a cluster


-Formed by the Session Factory


-Available across multiple sessions


-Can be configured on per class or per association basis.

Name some second level cache providers

EHCache, OSCache, SwarmCache, and JBossCache.

How do you configure a second level cache?

1. Choose a l2 cache vendor with the desired properties


2. in the hibernate configuration, include a cache provider tag


<property name="hibernate.cache.provider_class">


3. Set the cache properties in the cahce provider's xml or use annotations in the persistent class.

What are some common JPA annotations used in Hibernate?

@Entity Required


@Id Required


@Table Optional


@Column Optional

What is the general flow of a Hibernate communication with the RDBMS

1. Load the Hibernate configuration file and create a configuration object, which will automatically load all the hibernate mapping files.


2.Create session factory from the configuration object.


3.Get one session from the session factory.


4.create an HQL query or some kind of transaction.


5.Execute the query or transaction.

What is Hibernate Query Language (HQL)?

Hibernate offers a query language that embodies a very powerful and flexible mechanism to query, store, update, and retrieve objects from a database. This language, the HQL, is an object oriented extension to SQL.

How do you map Java Objects with the database tables?

Either use the appropriate annotations like Entity, Id, and Columns, or write an hbm.xml where you map the java class to the table and database columns to java class variables.

What's the difference between load and get?

load will throw an exception if the unique id doesn't exist in the database. Load only returns a proxy by default and an actual object will not be returned until the proxy is invoked. This should only be used when you are sure an object exists in the database at that id.



get will return null if the unique id is not found, and attempts to grab the object immediately. This can be used if you are unsure the object exists in the database.

What is the difference between merge and update?

Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session.

Define cascade and inverse option in one-many mapping.

cascade - enable operations to cascade to child entities.



cascade options: all/none/save-update/delete/all-delete-orphan



inverse - mark this collection as the inverse end of a bidirectional association.



inverse options: true/false



Essentially, inverse indicates which end of a relationship should be ignored So when persisting a parent who has a collection of children, should you ask the parent for its list of children, or ask the children who the parents are?

What is a named SQL query?

Named SQL queries are defined in the mapping xml document and called when required. You can use a session object to get a named query and set its parameters.

How do you invoke Stored Procedures in Hibernate

Stored procedures are defined in the mapping xml document and called where ever required.

What is the Criteria API in Hibernate?

Criteria is a simplified API for retrieving entitiyies by composing Criterion objects. This is a very convenient approach for functionality like search screens where ther eis a variable number of conditions to be placed upon a result set.

How do you switch between different relational databases?

For an Application managed datasource:


Change the driver properties (URL, username, password) to the new database and use the appropriate connector jar for the new database.



For a Server managed datasource:


Change the JNDI name to point to the new database.



Then change the Hibernate dialect to the correct dialect for the database.



All changes are either adding or removing a JAR connector and modifying the hibernate configuration xml.

What do you do if you want to see the Hibernate generated SQL?

In the Hibernate configuration file, change the property "show_sql" to true.


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

What is the difference between sorted and ordered in Hibernate?

Sorting is done through a java collection on the same JVM that is running Hibernate, after the data is read from the database.



Ordered is when the ordering occurs on the JVM of the database, initiated by an Order By clause in a query.



Large ordering operations should usually be done by the database, whereas smaller sorting operations should be done after grabbing the data from the database.

What types of collections are supported by hibernate?

SLAM Bag


Bag


Set


List


Array


Map

What are the ways to express joins in HQL?

HQL provides four ways of expressing inner and outer joins:


An Implicit association join


An ordinary join in the FROM clause


a fetch join in the FROM clause


a Theta style join in the WHERE clause.

What is the Hibernate proxy?

The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CHLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.

What is the use of dynamic-insert and dynamic update attributes in a class mapping?

Dynamic-update (defaults to false) specifies that UPDATE SQL should be generated at runtime and contains only those columns whose values have changed.



Dynamic-insert (defaults to false) specifies INSERT SQL should be generated at runtime and contain only the columns whose values are not null.



Efficiency!

What do you mean by fetching strategy?

A fetching strategy is the strategy Hibernate will use for retieving associated objects if the application needs to navigate the association. Fetch strategies may be declared in the ORM metadata or overridden by a particular HQL or Criteria query. Lazy/Eager loading.

What is automatic dirty checking?

Automatic dirty checking is a feature that saves us the effort of explicitly asking Hibernate to update the database when we modify the state of an object inside a transaction.

What is Transactional write-behind?

Hibernate uses a sophisticated algorithm to determine an efficient ordering that avoids database foreign key constraint violations but is still sufficiently predictable to the user. This feature is called transactional write-behind.

What are callback interfaces?

Callback interfaces allow the application to receive a notification when something interesting happens to an object, like during a CRUD operation. They are useful for certain generic functionalities.