Wednesday, January 6, 2016

What is DetachedCriteria in Hibernate ?

Ref:- https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/criterion/DetachedCriteria.html

public class DetachedCriteria
extends Object
implements CriteriaSpecification, Serializable
Some applications need to create criteria queries in "detached mode", where the Hibernate session is not available. This class may be instantiated anywhere, and then a Criteria may be obtained by passing a session to getExecutableCriteria(). All methods have the same semantics and behavior as the corresponding methods of the Criteria interface.

Monday, January 4, 2016

What is lazy loading?

Lazy loading is a technique in which objects are loaded on demand basis. Since Hibernate 3, lazy loading is by default, enabled so that child objects are not loaded when parent is loaded.

What is the difference between save() and persist() methods of session object?

session.save saves the object and returns the id of the instance whereas persist do not return anything after saving the instance.

Is SessionFactory a thread-safe object?

Yes, SessionFactory is a thread-safe and can be accessed by multiple threads simultaneously.

But Session is not thread-safe.

What’s difference between managed associations and hibernate associations?

Ref:- http://career.guru99.com/hibernate-interview-questions/

Managed associations relate to container management persistence and are bi-directional while hibernate associations are unidirectional.

What’s general hibernate flow using RDBMS?

Ref:- http://career.guru99.com/hibernate-interview-questions/

General hibernate flow involving RDBMS is as follows:
a. Load configuration file and create object of configuration class.
b. Using configuration object, create sessionFactory object.
c. From sessionFactory, get one session.
d. Create HQL query.
e. Execute HQL query and get the results. Results will be in the form of a list.

How can we map the classes as immutable?

Ref:- http://career.guru99.com/hibernate-interview-questions/

If we don’t want an application to update or delete objects of a class in hibernate, we can make the class as immutable by setting mutable=false