1/61
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is Hibernate?
An open-source Object-Relational Mapping (ORM) framework for Java.
What is the main purpose of Hibernate?
To map Java objects to relational database tables and manage persistence.
Is Hibernate a JPA implementation?
Yes, it is one of the most popular JPA providers.
What is the core interface in Hibernate?
Session
What is a Hibernate Session?
An interface for interacting with the database and managing persistent objects.
How do you obtain a Hibernate Session?
From a SessionFactory
What is a SessionFactory in Hibernate?
A factory for Session
objects, created once per application.
What is the configuration file used by Hibernate?
hibernate.cfg.xml
Which file defines database connection properties for Hibernate?
hibernate.cfg.xml
or persistence.xml
(if using JPA)
What is HQL?
Hibernate Query Language, similar to JPQL but specific to Hibernate.
How is HQL different from SQL?
HQL operates on entity objects and their properties, not tables and columns.
What is the purpose of @Entity
in Hibernate?
Marks a class as a persistent entity mapped to a database table.
What does @Table(name = "table_name")
do in Hibernate?
Specifies the name of the table to which the entity is mapped.
What is the use of @Id
in Hibernate?
It specifies the primary key of an entity.
What is the purpose of @GeneratedValue
?
Defines the strategy for primary key generation.
What are the key generation strategies in Hibernate?
AUTO, IDENTITY, SEQUENCE, TABLE
What is hibernate.dialect
?
A configuration property that tells Hibernate how to generate SQL for a specific database.
What does hibernate.show_sql
do?
Logs the generated SQL statements to the console.
What does hibernate.hbm2ddl.auto
control?
It controls schema generation: values include update
, create
, validate
, none
, etc.
What is lazy loading in Hibernate?
Objects are not fetched from the database until they are accessed.
What is eager loading in Hibernate?
Objects and their relationships are fetched immediately.
How do you control fetch type in Hibernate?
Using fetch = FetchType.LAZY
or FetchType.EAGER
in relationship annotations.
What is @OneToMany
used for?
To map one-to-many relationships between entities.
What is @ManyToOne
used for?
To define many-to-one relationships in entity mapping.
What is a proxy object in Hibernate?
A placeholder object used for lazy loading until the actual data is fetched.
What is the first-level cache in Hibernate?
A mandatory cache associated with the Session
object.
What is the second-level cache in Hibernate?
An optional shared cache across sessions managed by SessionFactory
.
Name common second-level cache providers.
Ehcache, Infinispan, Redis, Hazelcast.
What is query cache in Hibernate?
A cache for storing query result sets to improve performance.
How do you enable second-level cache in Hibernate?
Via hibernate.cfg.xml
and appropriate annotations like @Cache
.
What is cascading in Hibernate?
The ability to propagate operations (persist, merge, remove, etc.) from one entity to its relationships.
What is the difference between save()
and persist()
in Hibernate?
save()
returns ID and can be used outside transactions; persist()
is JPA-compliant and works within transactions.
What is the difference between merge()
and update()
in Hibernate?
merge()
copies changes to a managed instance; update()
reattaches a detached object.
What is a detached object in Hibernate?
An entity that is no longer associated with an active Hibernate session.
What does flush()
do in Hibernate?
Synchronizes the session state with the database.
What is clear()
in Hibernate?
Removes all entities from the session cache.
What is evict()
in Hibernate?
Removes a specific object from the session cache.
What is optimistic locking in Hibernate?
Prevents lost updates using version control (e.g., @Version
annotation).
What is pessimistic locking in Hibernate?
Prevents concurrent access using database-level locks.
What is @Version
used for in Hibernate?
To implement optimistic locking with a version column.
How can you execute native SQL in Hibernate?
Using createNativeQuery()
method from Session
or EntityManager
.
What is a Named Query in Hibernate?
A statically defined HQL or SQL query annotated with @NamedQuery
or @NamedNativeQuery
.
What is the purpose of Criteria
API in Hibernate?
To create object-oriented, type-safe queries without writing HQL or SQL.
What replaced Criteria API in JPA 2.0?
JPA Criteria API, which is more type-safe and strongly typed.
What is the Hibernate Validator?
A framework that integrates Bean Validation (JSR 380) into Hibernate entities.
How do you define constraints in Hibernate Validator?
Using annotations like @NotNull
, @Size
, @Min
, @Email
, etc.
What is @NaturalId
in Hibernate?
Used to define a unique business key alternative to the primary key.
Can Hibernate map composite primary keys?
Yes, using @EmbeddedId
or @IdClass
.
What is an embeddable class in Hibernate?
A reusable value object annotated with @Embeddable
and used with @Embedded
.
What is batch processing in Hibernate?
Processing multiple entities in batches to improve performance.
How do you configure batch size in Hibernate?
Using @BatchSize(size = N)
or hibernate.jdbc.batch_size
property.
What is N+1 Select problem in Hibernate?
A performance issue where fetching a collection results in one query for the parent and N queries for the children.
How do you avoid N+1 problem in Hibernate?
By using JOIN FETCH
, batch fetching, or entity graphs.
What is dirty checking in Hibernate?
Automatic detection and synchronization of changed fields with the database.
What is dynamic update in Hibernate?
An optimization where only modified fields are included in the SQL UPDATE statement.
What annotation enables dynamic update?
@DynamicUpdate
What is the difference between load()
and get()
in Hibernate?
load()
returns a proxy and may throw exception if not found; get()
returns null if the entity doesn't exist.
How do you configure Hibernate in a Spring Boot project?
Using application.properties
or application.yml
along with Spring Data JPA annotations.
What is the default fetch type for @OneToMany in Hibernate?
LAZY
What is the default fetch type for @ManyToOne in Hibernate?
EAGER
What does @Where
annotation do in Hibernate?
Adds a SQL fragment to filter entity associations or collections.
What is Hibernate Envers?
A module for auditing and versioning entity changes.