Hibernate
What is Second level Cache in Hibernate?
It is used at the SessionFactory level to give better performance by saving you round trips to the database
What does Session lock() method do in Hibernate?
It reattaches an object without synchronizing or updating the database
Can we make an Hibernate Entity Class final?
yes, but its not a good practice because Hibernate will not be able to use a proxy which will reduce performance.
What is Session in Hibernate? Can we share single Session among multiple threads in Hibernate?
A session is a unit of activity in Hibernate which cannot be shared among multiple threads because sessions are not thread-safe
Difference between get and load in Hibernate?
Main difference is that the get method will go to the database if the object is not found in the cache and return a fully initialized object, whereas load will return a proxy if object is not found in the cache.
What is SessionFactory in Hibernate? is SessionFactory thread-safe?
SessionFactory is factory used to create a Hibernate Session object and is thread-safe
What is named SQL query in Hibernate?
named query allows you to use a query based on a name that you provided in the configuration file using the <sql-query> tag
Why it's important to provide no argument constructor in Hibernate Entities?
because Hibernate creates an instance of those entities and you will receive an InstantiationException
What is difference between transient, persistent and detached object in Hibernate?
persistent objects are objects that are attached to a session; detached objects are objects that were previously attached to a session but not anymore; and transient objects are new instances of persistent classes, which are never directly associated with a Hibernate session.
What is query cache in Hibernate ?
query cache allows you to save queries for future calls and improves performance
Difference between save, persist and saveOrUpdate methods in Hibernate?
save is used to insert records whereas saveOrUpdate is used to insert or update records. Difference b/w save and persist is that save returns a serializable object while persist returns void
What is difference between sorted and ordered collection in hibernate?
sorted collection is sorted in memory by using the Java comparator, whereas the ordered collection uses the database's order by clause. For large datasets it is better to use ordered collection to avoid an OutOfMemory error