Professional Documents
Culture Documents
2. What is SessionFactory?
• The HQL query is created with the help of the following syntax: Session.createQuery
• Configuration
• Session
• SessionFactory
• Criteria
• Query
• Transaction
5. What is Session?
• The SQL query is created with the help of the following syntax:
Session.createSQLQuery
• Database Connection
• Class Mapping Setup
• No, Session is not a thread-safe object, many threads can access it simultaneously. In
other words, you can share it between threads
• No, collection mapping can only be performed with One-to-Many and Many-to-
Many.
save() persist()
returns the identifier (Serializable) of the
Return nothing because its return type is void.
instance.
Syntax: public Serializable save(Object o) Syntax: public void persist(Object o)
• One to One
• One to Many
• Many to One
• Many to Many
• A session is an object that maintains the connection between Java object application
and database. Session also has methods for storing, retrieving, modifying or deleting
data from database using methods like persist(), load(), get(), update(), delete(), etc.
17. What is the difference between first level cache and second level cache?
Second Level Cache First Level Cache
Second Level Cache is associated with
First Level Cache is associated with Session.
Session Factory.
It is not enabled by default. It is enabled by default.
• The objects of criteria are used for the creation and execution of the object-oriented
criteria queries.
load() get()
Throws ObjectNotFoundException if an
Returns null if an object is not found.
object is not found.
load() method doesn't hit the database. get() method always hit the database.
It returns proxy object. It returns the real object, not the proxy.
• If you mark a class as mutable="false", the class will be treated as an immutable class.
By default, it is mutable="true".
• Transient: The object is in a transient state if it is just created but has no primary key
(identifier) and not associated with a session.
• 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.
• Session
• Query
• Configuration
• Session Factory
• Criteria
• Transaction