1. What is persistence in Java with respect to databases?
A) The ability to define interfaces in Java
B) The process of compiling Java programs
C) Saving and retrieving Java objects to/from a database
D) Running Java programs from a web browser
Correct Answer: C
2. Which of the following best defines a Relational Database?
A) A storage of hierarchical objects in memory
B) A system that organizes data into tables, rows, and columns
C) A tool used to connect Java and XML
D) A graphical representation of object hierarchies
Correct Answer: B
3. Which SQL command is used to retrieve data from a database?
A) UPDATE
B) DELETE
C) INSERT
D) SELECT
Correct Answer: D
4. What is one major issue with persistence layers when mapping objects
to relational databases?
A) High memory usage
B) Object-relational impedance mismatch
C) Poor CPU performance
D) Inability to use SQL
Correct Answer: B
5. In Hibernate, which component is responsible for creating Session
objects?
A) Query
B) Transaction
C) SessionFactory
D) JDBC
Correct Answer: C
6. What is the main function of a Hibernate Session?
A) Managing configuration files
B) Performing CRUD operations on the database
C) Compiling Hibernate code
D) Creating threads for the application
Correct Answer: B
7. Which of the following problems is related to object identity in ORM?
A) Java uses surrogate keys
B) Java objects do not use references
C) Object identity (==) and object equality (equals()) differ from relational identity
D) Hibernate does not support primary keys
Correct Answer: C
8. Which interface in Hibernate manages commit and rollback
operations?
A) Session
B) Connection
C) Transaction
D) Statement
Correct Answer: C
9. What does ORM stand for in the context of Hibernate?
A) Object Runtime Mechanism
B) Object-Relational Mapping
C) Object Registration Model
D) Object Relationship Management
Correct Answer: B
10. Which of the following is NOT a benefit of using Hibernate?
A) Auto table creation
B) Automatic code compilation
C) Vendor independence
D) Caching support
Correct Answer: B
11. What is the main purpose of hibernate.cfg.xml file?
A) To define SQL queries
B) To load Java classes
C) To configure Hibernate and database settings
D) To compile Java code
Correct Answer: C
12. What is the role of the Transaction object in Hibernate?
A) To store data permanently
B) To handle user sessions
C) To ensure atomicity and consistency during database operations
D) To map Java objects to XML
Correct Answer: C
13. Which of the following is a correct way to open a Hibernate session?
A) SessionFactory.create()
B) SessionFactory.open()
C) factory.openSession()
D) Configuration.open()
Correct Answer: C
14. What problem does Hibernate solve compared to plain JDBC?
A) It increases code redundancy
B) It complicates database interaction
C) It abstracts SQL and provides object-level interaction
D) It avoids object orientation
Correct Answer: C
15. In Hibernate, which component is responsible for establishing a
connection with the database?
A) POJO
B) Configuration
C) Session
D) ConnectionProvider
Correct Answer: D
16. What does the term "granularity problem" refer to in ORM?
A) Tables being too small in size
B) Mismatch between class and table detail levels
C) Large databases being hard to maintain
D) SQL query optimization
Correct Answer: B
17. Which of the following is NOT part of the Hibernate architecture?
A) SessionFactory
B) Transaction
C) EntityManager
D) ConnectionProvider
Correct Answer: C
18. In Hibernate, what is a POJO?
A) A Java class with SQL annotations
B) A Java class without database logic
C) A configuration XML
D) A JDBC object
Correct Answer: B
19. Which of the following is true about SessionFactory?
A) It should be created for every transaction
B) It is a thread-safe singleton
C) It is used to run SQL queries directly
D) It is lightweight and non-reusable
Correct Answer: B
20. What does session.beginTransaction() do in Hibernate?
A) Creates a new database connection
B) Begins a new database transaction
C) Loads a new configuration
D) Opens a new session
Correct Answer: B
21. What is the correct order to perform a save operation in Hibernate?
A) Session → Transaction → Commit
B) Configuration → Query → Commit
C) Query → Session → Transaction
D) Session → Commit → Transaction
Correct Answer: A
22. Which of the following is used to configure Hibernate?
A) hibernate_config.java
B) hibernate.xml
C) hibernate.cfg.xml
D) hibernate.properties.xml
Correct Answer: C
23. Which method is used to persist an object in Hibernate?
A) saveObject()
B) store()
C) session.save()
D) insertData()
Correct Answer: C
24. What does Hibernate use for internal SQL generation?
A) JDBC
B) SQL Parser
C) Hibernate Query Language (HQL)
D) MyBatis
Correct Answer: C
25. What is the purpose of a Configuration object in Hibernate?
A) To define SQL statements
B) To manage sessions
C) To bootstrap Hibernate with config files
D) To manage cache
Correct Answer: C
26. Which of the following is NOT an ORM tool?
A) Hibernate
B) Dapper
C) JDBC
D) Sequelize
Correct Answer: C
27. Which annotation is used in Hibernate to mark a class as an entity?
A) @HibernateClass
B) @Mapped
C) @Entity
D) @Pojo
Correct Answer: C
28. What is the return type of session.createQuery() in Hibernate?
A) SQLQuery
B) ResultSet
C) Query
D) Statement
Correct Answer: C
29. Which of the following best describes the “identity problem” in ORM?
A) Difficulty identifying tables in a database
B) Mismanagement of foreign keys
C) Differences between object equality and database identity
D) Lack of authentication
Correct Answer: C
30. Which class in Hibernate is used to configure settings from
hibernate.cfg.xml?
A) Session
B) Transaction
C) Configuration
D) Mapping
Correct Answer: C
31. In which package is the Session interface located?
A) org.hibernate.core
B) javax.persistence
C) org.hibernate
D) com.hibernate.session
Correct Answer: C
32. Which method is used to close a session in Hibernate?
A) closeSession()
B) destroy()
C) session.close()
D) shutdown()
Correct Answer: C
33. What is hibernate.dialect used for?
A) To configure table names
B) To define connection URLs
C) To tell Hibernate the type of database
D) To enable logging
Correct Answer: C
34. Which is NOT a valid benefit of using Hibernate?
A) Auto table generation
B) Database vendor independence
C) High-level logging
D) Object-relational mapping
Correct Answer: C
35. What does the Criteria API provide in Hibernate?
A) Fast indexing
B) Manual SQL writing
C) Object-oriented query building
D) Table splitting
Correct Answer: C
36. Which keyword in SQL is used in combination with JOIN to filter data?
A) GROUP BY
B) HAVING
C) ON
D) INTO
Correct Answer: C
37. Which interface in Hibernate is used for executing dynamic queries
using object properties?
A) ResultSet
B) Criteria
C) Query
D) PreparedStatement
Correct Answer: B
38. What is the role of TransactionFactory in Hibernate?
A) To create SQL queries
B) To manage entity classes
C) To handle JDBC transactions
D) To configure and generate transaction instances
Correct Answer: D
39. How does Hibernate handle caching?
A) It does not support caching
B) Only with database support
C) Through first-level and second-level cache
D) Through Java serialization
Correct Answer: C
40. What does hibernate.show_sql do when set to true?
A) Shows Hibernate source code
B) Logs HQL queries
C) Displays generated SQL in console
D) Shows errors in XML
Correct Answer: C
41. What is the purpose of the @Table annotation in Hibernate?
A) It defines the entity
B) It specifies the table name in the database
C) It creates indexes
D) It stores session factory info
Correct Answer: B
42. What is the use of foreign key in relational databases?
A) To improve performance
B) To reduce storage
C) To maintain referential integrity
D) To sort records
Correct Answer: C
43. What is the role of DriverManager in JDBC?
A) To close database connections
B) To manage entity transactions
C) To load and manage JDBC drivers
D) To perform caching
Correct Answer: C
44. Which file is commonly used for Hibernate mapping metadata?
A) mapping.xml
B) hibernate-map.xml
C) orm.xml
D) hbm.xml
Correct Answer: D
1. Which annotation is used to mark a Java class as a Hibernate entity?
A) @POJO
B) @Table
C) @Entity
D) @Hibernate
Correct Answer: C
2. What does the @Id annotation signify in Hibernate?
A) Defines a transient field
B) Declares a primary key
C) Maps a foreign key
D) Identifies a session
Correct Answer: B
3. What does the @GeneratedValue annotation control?
A) Column length
B) Auto-generation of primary keys
C) Table name
D) Cache size
Correct Answer: B
4. What is the purpose of hibernate.cfg.xml?
A) To create tables manually
B) To define session lifecycle
C) To configure Hibernate settings
D) To store query results
Correct Answer: C
5. What does hibernate.hbm2ddl.auto = update do?
A) Prevents table creation
B) Forces schema validation
C) Automatically updates schema based on entity changes
D) Deletes all tables on startup
Correct Answer: C
6. Which method in Hibernate immediately returns the generated ID after
insert?
A) persist()
B) merge()
C) save()
D) flush()
Correct Answer: C
7. Which method throws an exception if the entity is not found?
A) get()
B) save()
C) persist()
D) load()
Correct Answer: D
8. Which method returns null if an entity is not found?
A) get()
B) load()
C) merge()
D) save()
Correct Answer: A
9. Which method is used to update a detached entity in Hibernate?
A) update()
B) save()
C) merge()
D) persist()
Correct Answer: C
10. What is the use of the evict() method?
A) Deletes an entity from DB
B) Flushes session
C) Detaches an entity from the session
D) Clears entire cache
Correct Answer: C
11. What does the flush() method do in Hibernate?
A) Deletes all entities
B) Forces execution of pending SQL operations
C) Closes session
D) Initializes objects
Correct Answer: B
12. What is the default return of save()?
A) void
B) entity object
C) generated ID
D) boolean
Correct Answer: C
13. Which annotation is used to prevent a field from being persisted?
A) @NotNull
B) @Ignore
C) @Transient
D) @Exclude
Correct Answer: C
14. What does @Lob represent in Hibernate?
A) Mapping logic
B) Collection mapping
C) Large object field (e.g., BLOB or CLOB)
D) Foreign key
Correct Answer: C
15. What does @Column annotation do?
A) Declares primary key
B) Ignores a field
C) Customizes column mapping
D) Converts entities to strings
Correct Answer: C
16. In a one-to-one relationship, what does the mappedBy attribute
indicate?
A) Owning side
B) Inverse side
C) Join table
D) Cascade level
Correct Answer: B
17. Which Hibernate annotation is used to embed an object inside
another?
A) @JoinColumn
B) @Entity
C) @Embedded
D) @Column
Correct Answer: C
18. Which is NOT a valid cascade type in Hibernate?
A) CascadeType.ALL
B) CascadeType.NONE
C) CascadeType.MERGE
D) CascadeType.REMOVE
Correct Answer: B
19. What does @OrderBy("employeeName ASC") do?
A) Sorts table names
B) Sorts fields alphabetically
C) Sorts associated entities
D) Sorts query results manually
Correct Answer: C
20. What is hibernate.show_sql = true used for?
A) Enabling transaction logs
B) Disabling queries
C) Printing SQL statements to console
D) Formatting XML
Correct Answer: C
21. Which method retrieves all objects of a given type?
A) session.findAll()
B) session.getAll()
C) session.createQuery("from Entity")
D) session.fetchAll()
Correct Answer: C
22. Which method is used to remove an entity from the database?
A) evict()
B) remove()
C) flush()
D) delete()
Correct Answer: D
23. What type of object does session.load() return initially?
A) null
B) Entity
C) Proxy
D) Query
Correct Answer: C
24. Which Hibernate object controls database transactions?
A) Transaction
B) Query
C) SessionFactory
D) Configuration
Correct Answer: A
25. Hibernate internally uses which technology for database operations?
A) JDBC
B) JSP
C) Spring
D) XML
Correct Answer: A
26. What is the purpose of SessionFactory?
A) Create configuration
B) Generate queries
C) Produce session objects
D) Log data
Correct Answer: C
27. What is the lifecycle stage where the main class persists the object?
A) Stage II
B) Stage III
C) Stage I
D) Stage V
Correct Answer: C
28. What file defines Maven dependencies for Hibernate?
A) pom.properties
B) build.gradle
C) pom.xml
D) dependencies.xml
Correct Answer: C
29. Which object must be closed to release database resources?
A) Configuration
B) Session
C) Query
D) Transaction
Correct Answer: B
30. What does hibernate.format_sql = true do?
A) Enables data compression
B) Formats SQL output for readability
C) Speeds up SQL execution
D) Displays metadata
Correct Answer: B
31. What does @ManyToOne define?
A) Join table mapping
B) One object relates to many others
C) Many entities map to one entity
D) One-to-one mapping
Correct Answer: C
32. What is the inverse side of a OneToOne mapping indicated by?
A) @OneToOne(inverse = true)
B) mappedBy
C) foreignKey
D) cascade
Correct Answer: B
33. Which operation ensures data is synchronized to the database
immediately?
A) clear()
B) flush()
C) merge()
D) load()
Correct Answer: B
34. When should merge() be preferred over update()?
A) Always
B) When entity is already managed
C) When entity is detached
D) When deleting an entity
Correct Answer: C
35. What is the return type of get() in Hibernate?
A) Proxy
B) void
C) Object
D) Query
Correct Answer: C
36. What will session.clear() do?
A) Remove entity from DB
B) Detach all managed objects from session
C) Drop database
D) Close the session
Correct Answer: B
37. What does @JoinColumn define?
A) A join query
B) The table schema
C) Foreign key in a relationship
D) New table name
Correct Answer: C
38. Which API is NOT standard in JPA but provided by Hibernate?
A) persist()
B) save()
C) merge()
D) remove()
Correct Answer: B
39. What will happen if get() doesn't find the record?
A) Exception is thrown
B) Application halts
C) Returns null
D) Creates the record
Correct Answer: C
40. What is the purpose of @Embeddable annotation?
A) Define relationships
B) Represent primary keys
C) Declare an embeddable object
D) Hide fields
Correct Answer: C
41. Hibernate allows table creation with which setting?
A) hibernate.table.create
B) hibernate.auto_create = true
C) hibernate.hbm2ddl.auto = create
D) table_generate = true
Correct Answer: C
42. Which annotation helps load associated collections in order?
A) @OrderBy
B) @Indexed
C) @Sort
D) @Ordered
Correct Answer: A
43. Which annotation allows BLOB storage in Hibernate?
A) @Blob
B) @Binary
C) @LargeData
D) @Lob
Correct Answer: D
44. Which method is best to use when you are not sure the object exists in
DB?
A) load()
B) save()
C) merge()
D) get()
Correct Answer: D
45. Which dependency is used in Maven to use Hibernate?
A) org.hibernate:hibernate-api
B) org.hibernate.orm:hibernate-core
C) javax.persistence:persistence-api
D) hibernate:core-impl
Correct Answer: B
46. How do you connect Hibernate to MySQL in XML?
A) hibernate.connection.driver = mysql
B) hibernate.connection.url
C) database.connector.mysql
D) hibernate.dialect = mysql
Correct Answer: B
47. What happens if transaction.commit() is skipped?
A) Nothing is affected
B) The session closes immediately
C) Data won’t be persisted
D) The application throws error
Correct Answer: C
48. What is the purpose of @ManyToOne in employee-department
relationship?
A) One employee is linked to many departments
B) One department can have many employees
C) Prevent duplicate records
D) Used for embedding
Correct Answer: B
49. Which API supports lazy-loading proxy creation?
A) JDBC
B) Hibernate
C) JPA only
D) Spring JDBC
Correct Answer: B
50. Which annotation is used to exclude computed fields from being
persisted?
A) @Exclude
B) @Ignore
C) @NotPersist
D) @Transient
Correct Answer: D
1. What does @OneToOne(fetch = FetchType.EAGER) imply?
A) The associated entity is fetched only when accessed
B) The association is ignored
C) The associated entity is fetched immediately with the parent
D) It defines a join table
Correct Answer: C
2. What is the default fetch type for @OneToOne in Hibernate?
A) Lazy
B) Eager
C) None
D) Optional
Correct Answer: B
3. What is the inverse side in a one-to-one relationship?
A) The side with the @JoinColumn
B) The side with the mappedBy attribute
C) The side that deletes the record
D) The one that uses @Transient
Correct Answer: B
4. In a one-to-many mapping, what type of list is typically used to store
the child entities?
A) HashMap
B) Set
C) List
D) Array
Correct Answer: C
5. Which annotation is used in the child entity of a One-to-Many
relationship?
A) @OneToMany
B) @ManyToOne
C) @JoinTable
D) @Embedded
Correct Answer: B
6. What does orphanRemoval = true do in a One-to-Many mapping?
A) Prevents entity deletion
B) Deletes child entities removed from the parent's collection
C) Detaches the session
D) Deletes the parent entity
Correct Answer: B
7. What kind of table is used in a Many-to-Many relationship?
A) Temporary table
B) Join table
C) Indexed table
D) External table
Correct Answer: B
8. What is the default fetch type for @ManyToMany?
A) EAGER
B) IMMEDIATE
C) LAZY
D) FETCH
Correct Answer: C
9. Which annotation defines the owning side of a Many-to-Many
relationship?
A) @JoinColumn
B) @MappedBy
C) @JoinTable
D) @Entity
Correct Answer: C
10. In Hibernate, what is the primary purpose of FetchType.LAZY?
A) Eagerly load associated data
B) Immediately execute a query
C) Load associated data only when accessed
D) Load the full database
Correct Answer: C
11. What is the lifecycle state of a new object not yet associated with a
Hibernate session?
A) Detached
B) Transient
C) Persistent
D) Removed
Correct Answer: B
12. Which state means the object is being tracked and stored by
Hibernate?
A) Transient
B) Detached
C) Removed
D) Persistent
Correct Answer: D
13. What happens when a session is closed?
A) All objects become transient
B) All persistent objects become detached
C) The database is reset
D) The cache is cleared permanently
Correct Answer: B
14. What is the correct method to reattach a detached entity?
A) merge()
B) evict()
C) clear()
D) save()
Correct Answer: A
15. What query language is used in Hibernate for object-based queries?
A) SQL
B) HQL
C) JPQL
D) PQL
Correct Answer: B
16. Which clause in HQL retrieves data from an entity?
A) SHOW
B) FETCH
C) SELECT
D) PRINT
Correct Answer: C
17. HQL queries operate on which of the following?
A) Tables and columns
B) Views and procedures
C) Objects and their properties
D) Cursors
Correct Answer: C
18. What is the keyword used in HQL to filter query results?
A) HAVING
B) WHERE
C) FILTER
D) VALIDATE
Correct Answer: B
19. Which HQL clause is used for sorting the results?
A) SORT
B) FILTER
C) ORDER BY
D) GROUP BY
Correct Answer: C
20. What is the default fetch type for @OneToMany?
A) EAGER
B) IMMEDIATE
C) LAZY
D) DYNAMIC
Correct Answer: C
21. What annotation is used to define a many-to-one relationship?
A) @ManyToOne
B) @JoinTable
C) @OneToMany
D) @ManyToMany
Correct Answer: A
22. In Hibernate, what is the result of a session.remove() call followed
by commit()?
A) The entity is cached
B) The entity is detached
C) The entity is deleted from DB
D) The session is closed
Correct Answer: C
23. What does session.save() return?
A) boolean
B) Generated ID
C) void
D) ResultSet
Correct Answer: B
24. Which method transitions a detached object to persistent state
again?
A) saveOrUpdate()
B) evict()
C) clear()
D) delete()
Correct Answer: A
25. Which HQL method allows paginated results?
A) setStart()
B) setOffset()
C) setFirstResult() and setMaxResults()
D) limit()
Correct Answer: C
26. What is the correct syntax to update a record using HQL?
A) UPDATE TABLE
B) UPDATE Student SET
C) UPDATE Student S SET
D) MODIFY Student
Correct Answer: C
27. In HQL, how do you delete records based on condition?
A) DELETE FROM WHERE
B) REMOVE FROM
C) DELETE Student WHERE
D) DELETE FROM Student WHERE
Correct Answer: D
28. What is the proper method to execute an HQL update query?
A) executeUpdate()
B) run()
C) flush()
D) save()
Correct Answer: A
29. What does the HQL keyword JOIN FETCH do?
A) Deletes all joins
B) Fetches associated entity eagerly
C) Creates new session
D) Replaces lazy with transient
Correct Answer: B
30. What is the purpose of a NamedQuery in Hibernate?
A) Hides the entity
B) Auto-executes queries
C) Pre-defines reusable queries
D) Stores class names
Correct Answer: C
31. What is required for a named query to work?
A) Configuration file
B) Annotation on method
C) Annotation in entity class
D) .sql file
Correct Answer: C
32. What annotation is used to declare a native SQL named query?
A) @NativeSQL
B) @SQLQuery
C) @NamedNativeQuery
D) @RawSQL
Correct Answer: C
33. Which HQL clause is used to group records?
A) ORDER
B) GROUP BY
C) AGGREGATE
D) SUMMARY
Correct Answer: B
34. What type of query is used to fetch students with more than one
course?
A) Named query
B) Subquery
C) Filter
D) Delete query
Correct Answer: B
35. Which aggregate function is valid in HQL?
A) TOTAL()
B) COUNT()
C) SIZE()
D) GROUP()
Correct Answer: B
36. What does FetchType.EAGER do?
A) Loads only when accessed
B) Loads entities in parallel
C) Loads entities immediately
D) Skips loading altogether
Correct Answer: C
37. Which keyword allows counting rows in HQL?
A) SIZE
B) TOTAL
C) COUNT
D) AMOUNT
Correct Answer: C
38. When does a persistent object become detached?
A) On save()
B) On flush()
C) On session.close()
D) On creation
Correct Answer: C
39. Which of the following is true about Detached state?
A) Object is garbage collected
B) Object is never stored in DB
C) Object is no longer managed by session
D) Object cannot be reused
Correct Answer: C
40. What is the return type of session.createQuery(...).list()?
A) ResultSet
B) Array
C) List
D) Map
Correct Answer: C
41. In a JOIN clause, what does S.course refer to?
A) Table column
B) Class name
C) Field name in entity
D) Session name
Correct Answer: C
42. What is the correct syntax for a join in HQL?
A) JOIN TABLE course
B) JOIN Student.course
C) JOIN S.course
D) INNER S JOIN course
Correct Answer: C
43. Which feature helps Hibernate fetch associated entities with a single
query?
A) Batch processing
B) JOIN FETCH
C) Named Native Query
D) Cascade
Correct Answer: B
44. When using JOIN FETCH, which clause must you avoid to prevent
Cartesian product issues?
A) WHERE
B) FROM
C) JOIN
D) ORDER BY
Correct Answer: D
45. Which function allows multiple queries in a single annotation block?
A) @Queries
B) @MultipleQuery
C) @NamedQueries
D) @QueryGroup
Correct Answer: C
46. Which annotation defines an HQL-based NamedQuery?
A) @NamedQuery
B) @HQLQuery
C) @Query
D) @JPQL
Correct Answer: A
47. What is one key benefit of Named Queries?
A) Encryption
B) Compilation speed
C) Reusability and maintainability
D) Detaching session
Correct Answer: C
48. Which HQL feature helps with pagination?
A) @Paginated
B) query.page()
C) setMaxResults(), setFirstResult()
D) LIMIT OFFSET
Correct Answer: C
49. Which keyword is used in HQL to retrieve only specific fields?
A) SHOW
B) SELECT
C) OUTPUT
D) DISPLAY
Correct Answer: B
50. In Hibernate, which keyword executes a DML operation in HQL 6+?
A) session.execute()
B) createQuery()
C) createMutationQuery()
D) createSQLQuery()
Correct Answer: C
1. What is the primary purpose of a Named Query in Hibernate?
A) Define relationships between entities
B) Predefine reusable queries
C) Initialize session factory
D) Format SQL output
Correct Answer: B
2. Which annotation is used for multiple HQL Named Queries?
A) @NamedQueryGroup
B) @NamedSQLQueries
C) @NamedQueries
D) @MultiQuery
Correct Answer: C
3. Which method is used to execute a NamedQuery?
A) session.executeNamed()
B) session.queryNamed()
C) session.createNamedQuery()
D) session.namedQueryExecute()
Correct Answer: C
4. Which two methods help implement pagination in Hibernate HQL?
A) setOffset() and limit()
B) setFirstResult() and setMaxResults()
C) offsetStart() and maxResults()
D) getRows() and skipRows()
Correct Answer: B
5. What is the benefit of using pagination in Hibernate?
A) Slows down response
B) Increases memory use
C) Efficient chunk-wise data retrieval
D) Skips data processing
Correct Answer: C
6. What does setFirstResult(0) do?
A) Starts from the 1st record
B) Starts from the 2nd record
C) Sets the max record count
D) Fetches the last record
Correct Answer: A
7. What does pageNumber = 3, pageSize = 10 fetch?
A) Records 0-9
B) Records 10-19
C) Records 20-29
D) Records 30-39
Correct Answer: C
8. Which Hibernate method is used for native SQL queries?
A) createQuery()
B) createSQLQuery()
C) createNativeQuery()
D) runSQL()
Correct Answer: C
9. What does createNativeQuery(..., Entity.class) return?
A) Array
B) POJO objects of that entity
C) String
D) ResultSet
Correct Answer: B
10. How can scalar values (like id, name) be fetched using native SQL?
A) getScalarValues()
B) session.executeScalar()
C) query.getResultList() with Object[]
D) scalarQuery.fetch()
Correct Answer: C
11. Which method is used to update data via native SQL in Hibernate?
A) save()
B) persist()
C) query.executeUpdate()
D) executeBatch()
Correct Answer: C
12. What does CascadeType.ALL include?
A) Only persist
B) Persist and merge
C) All operations like persist, merge, remove, detach
D) Only delete
Correct Answer: C
13. Which cascade type ensures child is saved with the parent?
A) CascadeType.MERGE
B) CascadeType.REMOVE
C) CascadeType.PERSIST
D) CascadeType.DETACH
Correct Answer: C
14. What is the effect of CascadeType.REMOVE?
A) Nothing happens
B) Removes parent only
C) Removes both parent and children
D) Removes configuration
Correct Answer: C
15. What is the first level cache in Hibernate?
A) Manual
B) Shared across sessions
C) Disabled by default
D) Built-in, session-scoped cache
Correct Answer: D
16. When is first-level cache cleared?
A) On query execution
B) On HibernateUtil shutdown
C) When session is closed
D) After flush()
Correct Answer: C
17. Which cache works across sessions and must be configured?
A) First-level
B) JDBC cache
C) Memory cache
D) Second-level cache
Correct Answer: D
18. What is the role of @Cacheable annotation?
A) Logs the cache
B) Enables entity caching
C) Deletes the cache
D) Clears session
Correct Answer: B
19. Which caching strategy supports both reads and writes?
A) READ_ONLY
B) READ_WRITE
C) WRITE_ONLY
D) LAZY
Correct Answer: B
20. What does timeToIdleSeconds=300 in Ehcache mean?
A) Data expires after 5 minutes of no access
B) Data lives forever
C) Data deleted after 3 minutes
D) Data is re-fetched on every query
Correct Answer: A
21. What does timeToLiveSeconds=600 do?
A) Cache dies after app closes
B) Cache expires after 600 seconds regardless of usage
C) Cache is deleted if memory full
D) Query runs every 10 minutes
Correct Answer: B
22. What eviction policy does LRU stand for?
A) Least Recently Updated
B) Last Retried Update
C) Least Recently Used
D) Last Random Usage
Correct Answer: C
23. Which cache tag configures entity-specific caching in Ehcache?
A) <defaultEntityCache>
B) <entityCache>
C) <cache name="Entity">
D) <ehcacheEntity>
Correct Answer: C
24. What happens when maxEntriesLocalHeap is reached?
A) Cache stops working
B) App crashes
C) Entries are evicted based on policy
D) Database is cleared
Correct Answer: C
25. Which Maven dependency enables second-level caching in
Hibernate?
A) hibernate-core
B) hibernate-jdbc
C) hibernate-ehcache
D) hibernate-utils
Correct Answer: C
26. In Hibernate, which cache is enabled by default?
A) Third-level
B) Query cache
C) First-level
D) Ehcache
Correct Answer: C
27. Which property enables query-level caching in Hibernate?
A) hibernate.query.cache.enable
B) hibernate.cache.query_enabled
C) hibernate.cache.use_query_cache
D) query.cache.mode
Correct Answer: C
28. In which file is <ehcache> configuration placed?
A) hibernate.cfg.xml
B) pom.xml
C) ehcache.xml
D) application.yml
Correct Answer: C
29. What is the default cache strategy if no custom cache is defined?
A) No cache
B) Hard eviction
C) defaultCache
D) LRU cache
Correct Answer: C
30. What is the benefit of second-level caching?
A) Faster UI rendering
B) Session-independent entity caching
C) Logging SQL queries
D) Paging optimization
Correct Answer: B
31. What is the max value of pageNo = 0 in pagination?
A) No page
B) First record (index 0)
C) Starts from 10
D) Starts from page 10
Correct Answer: B
32. What does pagination prevent?
A) Too many DB connections
B) Over-fetching of data
C) Indexing
D) Auto-flushing
Correct Answer: B
33. What kind of values are returned by native query using scalar
projection?
A) Entity
B) Object[]
C) Integer
D) Session
Correct Answer: B
34. Which feature automatically applies operations to children based on
parent operations?
A) Lazy loading
B) Cascading
C) Fetching strategy
D) Second-level cache
Correct Answer: B
35. In a One-to-Many cascade example, which entity is the parent?
A) Employee
B) Manager
C) Department
D) Project
Correct Answer: C
36. Which cache strategy does NOT allow updates?
A) READ_WRITE
B) NONSTRICT_READ_WRITE
C) READ_ONLY
D) LRU
Correct Answer: C
37. In HQL pagination, what does setMaxResults(10) imply?
A) Fetch only the 10th record
B) Fetch at most 10 records
C) Start from 10
D) Fetch from last 10
Correct Answer: B
38. What does session.get() return when entity is not found?
A) Null
B) Exception
C) 0
D) Warning
Correct Answer: A
39. Which feature does @Cache(usage =
CacheConcurrencyStrategy.READ_WRITE) enable?
A) Session logging
B) Read and write consistency for cached entities
C) Data export
D) Query debugging
Correct Answer: B
40. How are entity changes reflected in DB with second-level cache?
A) Automatically via cache sync
B) Only on flush
C) Only if first-level cache is disabled
D) Cache must be cleared first
Correct Answer: A
41. What does a persistent object mean in Hibernate?
A) Not stored in DB
B) Not linked to session
C) Associated with session and DB
D) Ignored during flush
Correct Answer: C
42. What is stored in second-level cache?
A) Class references
B) SessionFactory
C) Entity objects
D) Files
Correct Answer: C
43. Which Hibernate feature enables real-time updates to related
entities?
A) Lazy loading
B) Cascade MERGE
C) Manual commit
D) Cache clear
Correct Answer: B
44. Which field is required for pagination with sorting?
A) sortField
B) sortOrder
C) filter
D) cacheType
Correct Answer: A
45. What is required to cache a class in Hibernate?
A) @SessionScoped
B) @Id only
C) @Cacheable annotation
D) Serializable
Correct Answer: C
46. What does .list() return in a query?
A) Map
B) Object[]
C) List of results
D) Entity name
Correct Answer: C
47. How does Hibernate reduce DB load during repeated entity access?
A) Logging
B) Lazy loading
C) First-level cache
D) HQL
Correct Answer: C
48. What is the eviction policy that removes oldest cached items first?
A) LRU
B) LFU
C) FIFO
D) RANDOM
Correct Answer: C
49. What cache provider is used in the example project?
A) Infinispan
B) Redis
C) Ehcache
D) OSCache
Correct Answer: C
50. Which Hibernate component shares the second-level cache?
A) Session
B) Transaction
C) SessionFactory
D) Configuration
Correct Answer: C