How do you invoke Stored Procedures ?

<sql-query name="selectAllEmployees_SP" callable="true">
 <return alias="emp" class="employee">
   <return-property name="empid" column="EMP_ID"/>       

   <return-property name="name" column="EMP_NAME"/>       
   <return-property name="address" column="EMP_ADDRESS"/>
    { ? = call selectAllEmployees() }

What is Query Timeout in Hibernate ?

Query object lets you control the amount of time that a query is allowed to reside on the database server. Using the setTimeout(int) method, you can give the query object x number of seconds to execute before it is cancelled. When you are working on production systems, it is vital that queries not be allowed to take infinite or unreasonable amounts of time to execute. By using the timeout functionality as well as the methods to limit the number of rows returned by the query, you can provide the user with fast results.

What properties are available for cache setup in Hibernate ?

hibernate.cache.provider_class: Indicates the class name of a custom CacheProvider. For example, classname.of.CacheProvider.

hibernate.cache.use_minimal_puts: Optimizes second-level cache operation to minimize writes, at the cost of more frequent reads (useful for clustered caches). Possible values are true and false.

hibernate.cache.use_query_cache: Enables the query cache. The query cache is disabled by default. Possible values are true and false.

hibernate.cache.region_prefix: Provides a prefix to use for second-level cache region names. For example, prefix.

The two important properties are hibernate.cache.provider_class and hibernate.cache.use_query_cache. By default, Hibernate is configured to use the EHCache class for the second-level cache. If you need to change the cache type, specify the hibernate.cache.provider_class property for the cache you want.

What is read-write cache in Hibernate ?

When objects being cached need to be updated, the read-write usage mechanism is an appropriate option to choose. As you might expect, the time requirements for supporting a read-write cache are more involved than in a read-only situation.

What is nonrestrict read-write cache in Hibernate ?

The nonstrict read-write cache mechanism works in the same fashion and has the same rules as the readwrite cache usage described in the previous section, but you can use it when an application will only occasionally update the application objects. Using this cache usage relaxes the transaction isolation provided in the read-write pattern.

What is transactional cache in Hibernate ?

Of the built-in provider classes, the JBoss TreeCache is the only one that fully supports a transactional cache strategy. You can only use this provider in a JTA environment. It provides a high level of support for caching objects when used with JTA.

What is evict() method in Hibernate ?

The method is designed to both remove and identify objects in the cache. The primary role of the method is to permanently remove object from the cache. If the object is currently part of a transaction, it is removed from the cache. No rules block an object from being removed. The evict() method removes a specific object from the Session object’s cache.

public void evict(Object object);

What is clear() method in Hibernate ?

The method is designed to both remove and identify objects in the cache. The familiar evict() method removes a specific object from the Session object’s cache. The clear() method clears the entire cache.

public void clear();

What is contains() method in Hibernate ?

The method is designed to identify objects in the cache. The contains() method returns a boolean value depending on whether the specified object exist in the persistent store.

boolean contains(Object object);

What is getIdentifier() method in Hibernate ?

The method is designed to identify objects in the cache. The getIdentifier() method works in much the same way as above three methods, except it returns the identifier of the supplied object if it exists in the cache; otherwise an exception is thrown.

Serializable getIdentifier(Object object);

What are the available transaction attributes in Hibernate ?

Required: This option will guarantee that all of the statements within the method are part of a transaction.

RequiresNew: This option tells the manager to commit the results unconditionally.

NotSupported: This option tells the manager to not use a transaction.

Supports: This option tells the manager to use a transaction if the caller is part of a transaction.

Mandatory: This option tells the manager to always use transactions.

Never:This option tells the manager to never use a transaction.

What are transient, persistent and detached Objects in Hibernate ?

Transient State

A New instance of  a persistent class which is not associated with a Session, has no representation in the database and no identifier value is considered transient by Hibernate:

UserInfo user = new UserInfo();
// user is in a transient state

Persistent State

A persistent instance has a representation in the database , an identifier value and is associated with a Session.

We can make a transient instance persistent by associating it with a Session:

Long id = (Long);
// user is now in a persistent state

Detached State

Now, if we close the Hibernate Session, the persistent instance will become a detached instance: it isn’t attached to a Session anymore (but can still be modified and reattached to a new Session later though).

//user in detached stat