R4R
Right Place For Right Person TM
 
R4R Java Hibernate Hibernate FAQs Hibernate Interview Questions and Answers

 


Tolal:100 Click: 1 2 3 4 5
Previous Home Next

Hiber Interview Questions And Answers

Page 1

Ques: 1 
Explain about HibernateTemplate?

Ans:
The org.springframework.orm.hibernate.HibernateTemplate class simplifies Hibernate data access code, and converts checked HibernateExceptions into unchecked DataAccessExceptions, following the org.springframework.dao exception hierarchy. Uses the same SQLExceptionTranslator mechanism as JdbcTemplate. The central method is execute(), supporting Hibernate access code implementing the HibernateCallback interface. It provides Hibernate Session handling such that neither the HibernateCallback implementation nor the calling code needs to explicitly care about retrieving/closing Hibernate Sessions, or handling Session lifecycle exceptions.

Ques: 2 
What happens when both hibernate.properties and hibernate.cfg.xml are in the classpath?

Ans:
The settings of the XML configuration file will override the settings used in the properties.

Ques: 3 
What are the types of Hibernate instance states ?

Ans:
There are three types of instance states in Hibernate: * Transient :-The instance is not associated with any persistence context * Persistent :-The instance is associated with a persistence context * Detached -:The instance was associated with a persistence context which has been closed – currently not associated.

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

Ans:
You may declare a persistent class using the class element. The dynamic-insert and dynamic-update attributes are optional attributes. The dynamic-update (defaults value is false), specifies that UPDATE SQL should be generated at runtime and contain only those columns whose values have changed. The dynamic-insert (defaults value is false), specifies that INSERT SQL should be generated at runtime and contain only the columns whose values are not null.

Ques: 5 
How can you map a whole class as immutable?

Ans:
You can mark the class as mutable="false", Default value is true. This specifies that instances of the class are mutable. You can not update or delete immutable classes by the application.

Ques: 6 
What is Connection pools used for in Hibernate?

Ans:
Connection pools are a common way to improve application performance. Rather than opening a separate connection to the database for each request, the connection pool maintains a collection of open database connections that are reused. Application servers often provide their own connection pools using a JNDI DataSource, which Hibernate can take advantage of when configured to use a DataSource. When you choose a connection pooling service, you must configure it for your environment. Hibernate supports configuring connection pools from the hibernate.cfg.xml file. The connection.provider_class property sets the pooling implementation: <property name="connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider </property>

Ques: 7 
How will you configure the SessionFactory?

Ans:
The Configuration class kicks off the runtime portion of Hibernate. It's used to load the mapping files and create a SessionFactory for those mapping files. There are three ways to create and initialize a Configuration object. This first snippet loads the properties and mapping files defined in the hibernate.cfg.xml file and creates the SessionFactory: Configuration cfg =new Configuration(); SessionFactory factory =cfg.configure().buildSessionFactory(); The configure()method tells Hibernate to load the hibernate.cfg.xml file. The Configuration class can also load mapping documents programmatically: Configuration cfg =new Configuration(); cfg.addFile("com/manning/hq/ch03/Event.hbm.xml"); Another alternative is to have Hibernate load the mapping document based on the persistent class.

Ques: 8 
What are the  Joined Subclasses  in Hibernate?

Ans:
Joined subclasses are those that are mapped to a table-per-subclass design rather than a table-per-hierarchy. In Hibernate, this could be mapped as follows: <class name="Foo" table="foo"> ... <property name="name" column="name" type="string" <joined-subclass name="subclass.Bar" table="bar"> <key column="foo_id"/> <property name="age" column="age" type="string"/> </joined-subclass> </class>

Ques: 9 
What are the various advantages of Hibernate?

Ans:
Advantages of Hibernate: * Retains natural object model (transparent) * Minimizes Code * Does not require a container * Model is not tied to persistence implementation. * Metadata controlled persistence * Transparent - working with the model, not the data access technology * Pooling, Caching, Transactions can all be handled outside of our code

Ques: 10 
What are the different caching services provided by the Hibernate?

Ans:
Hibernate supports four different caching services. EHCache (Easy Hibernate Cache) is the default service. If you prefer to use an alternative cache, you need to set the cache.provider_class property in the hibernate.cfg.xml file: <property name="cache.provider_class"> org.hibernate.cache.OSCacheProvider </property> This snippet sets the cache provider to the OSCache caching service. Caching Services Supported by Hibernate: * EHCache * OSCache * SwarmCache * TreeCache

Ques: 11 Explain the Fetching association in HQL?

Ans:
In HQL, you can specify that an association should be eagerly fetched by an outer join using the fetch keyword in the 'from' clause: from Item item left join fetch item.bids where item.description like '%gc' This query returns all items with a description that contains the string gc, and all their bids, in a single select. When executed, it returns a list of Item instances with there 'bids' collection fully initialized. We call this a 'from' clause.

Ques: 12 
What are the Hibernate join options?

Ans:
In Hibernate queries, you don't usually specify a join condition explicitly. Rather you specify the name of a mapped Java class association. HQL provides four ways of expressing (inner and outer) joins: * An 'ordinary' join in the 'from' clause. * A 'fetch' join in the 'from' clause. * A 'theta-style' join in the 'where' clause. * An 'implicit' association join.

Ques: 13 
Which interfaces are defined to execute the query in the Hibernate?

Ans:
The following interfaces are defined to execute the query: * Query interface * Criteria interface Both interfaces define several methods for controlling execution of a query. To create a new Query instance, call either createQuery() or createSQLQuery(). The createQuery() method prepares an HQL query: Query q = session.createSQLQuery( "select {u.*} from USERS {u}", "u", User.class); To obtain a Criteria instance, call createCriteria(), passing the class of the objects you want the quety to return. This is also called the root entity of the criteria query, the User in this example: Criteria c = session.createCriteria(User.class);

Ques: 14 
What are the various mapping association in Hibernate?

Ans:
When we use word associations, we are always referring to relationships between entities. The various mapping association in Hibernate: * One-to-one associations * Many-to-many association

Ques: 15 
What are the various built-in-mapping types available in Hibernate?

Ans:
Hibernate built-in mapping types usually share the name of the Java type they map; however, there may be more than one Hibernate mapping type for a partucular Java type. The various built-in-mapping types available in Hibernate are: * Java primitive mapping types * Date and time mapping types * Large object mapping types * Various JDK mapping types

Ques: 16 
What are the various built-in concurrency strategies for transaction used in Hibernate?

Ans:
A concurrency strategy is a mediator, it's responsible for storing items of data in the cache and retrieving them from the cache. There are four built in concurrency strategies, representing decreasing levels of strictness in terms of transaction isolation: * transactional :- Available in a managed environment only. It guarantees full transactional isolation upto repeatable read, if required. * read-write :- Maintains read committed isolation, using a timestamping mechanism. It's available only in non-clustered environments. * nonstrict-read-write :- Makes no guarantee of consistency between the cache and the database. If there is a possibility of concurrent access to the same entity , you should configure a sufficiently short expiry timeout. Otherwise you may read stale data in the catch. * read-only :- A concurrency strategy suitable for data which never changes. Use it for reference data only.

Ques: 17 
What are the various Catching strategies in Hibernate?

Ans:
Catching is such a fundamental concept in object/ralational persistence that you can't understand the performance, scalability, or transactional semantics of an ORM implementation without first knowing what kind of catching strategy it uses. There are three types of cache: * Transaction scope :- Attached to the current unit of work, which may be an actual database transaction or an application transaction. Every unit of work has its own cache. * Process scope :- Shared among many unit of work or transaction. * Cluster scope :- Shared among multiple processes on the same machine or among the multiple machines in a cluster. It requires some kind of remote process communication to maintain consistency.

Ques: 18 How will you set the isolation level for database in JDBC connection?

Ans:
Every JDBC connection to a database uses the database's default isolation level, usually read committed or repeatable read. This default can be changed in the database configuration. You may also set the transaction isolation for JDBC connection using a Hibernate configuration option: hibernate.connection.isolation = 4 Hibernate will then set this isolation level on every JDBC connection obtained from a connection pool before starting a transaction. The sensible values for this option are as follows: * 1-Read uncommitted isolation * 2-Read committed isolation * 4-Repeatable read isolation * 8-Serializable isolation

Ques: 19 
Explain the Phantom read?

Ans:
A transaction executes a query twice, and the second result set includes rows that weren't visible in the first result set. This situation is caused by another transaction inserting new rows between the execution of the two queries.

Ques: 20 
Describe the various isolation levels defined by ANSI SQL standart?

Ans:
The standart isolation levels are defined by the ANSI SQL standard but aren't particular to SQL databases: * Read uncommitted :- Permits dirty read but not lost updates. One transaction may not write to a row if another committed transaction has already written to it. * Read committed :- Permits unrepeatable reads but not dirty reads. * Repeatable reads :- Permits neither unrepeatable reads nor dirty reads. Phantom reads may occur. * Serializable :- Provides the strictest transaction isolation. It emulates serial transaction execution, as if transaction has been executed one after another, serially, rather than concurrently.


Goto Page:

1 2 3 4 5
Share |

Hiber Objective

Hiber Objective Questions And Answers

Hiber Interview Questions And Answers

Hiber Subjective Questions And Answers

R4R,Hiber Objective, Hiber Subjective, Hiber Interview Questions And Answers,Hiber,Hiber Interview,Hiber Questions ,Hiber Answers

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R