HibernateNotes
HibernateNotes
https://www.interviewbit.com/hibernate-interview-questions/
https://www.javatpoint.com/hibernate-interview-questions
Hibernate:
1)MySQL
2)Oracle
3)HSQL
4)PostgreSQL
2)What is SessionFactory ?
SessionFactory provides the instance of Session.It holds the data of second level
cache that is not enabled by default.
The org.hibernate.SessionFactory interface provides factory method to get the
object of Session.
4)What is Session?
It holds a first-level cache of data. The org.hibernate.Session interface provides
methods to insert, update and delete the object.
10) What are the states of the object in hibernate?(Life cycle of Object in
Hibernate)
There are 3 states of the object (instance) in hibernate.
Persistent: The object is in a persistent state if a session is open, and you just
saved the
instance in the database or retrieved the instance from the database.
Detached: The object is in a detached state if a session is closed.
After detached state, the object comes to persistent state if you call lock() or
update() method.
If we are using the XML form of configuration, then a class can be made immutable
by marking mutable=false.
The default value is true there which indicating that the class was not created by
default.
Since Hibernate 3, lazy loading is enabled by default, and you don't need to do
lazy="true". It means not to load the child objects when the parent is loaded.
It means it will load the child objects when the parent is loaded.
Database independent.
Simple to write a query.
17)What is the difference between first level cache and second level cache?
3) The first level cache is available only until the session is open,
3) The second-level cache is available through the
the first level cache is destroyed. once the session is closed,
application’s life cycle, It is only destroyed when application is stopped.
hibernate.cfg.xml
There must be one configuration file for each database used in the application,
suppose if we want to connect with 2 databases, then we must create 2
configuration files with different names.
Hibernate.properties