Hibernate Test 1 — Questions and Answers
Question 1: In Hibernate, what is Query Level Cache?
- The query-level cache is the Session based cache
- The query-level cache is a query resultset cache that works in tandem with the second-level cache. (Correct answer)
- Both of the above
- None of the above
Correct answer: The query-level cache is a query resultset cache that works in tandem with the second-level cache.
Explanation: <br> Hibernate includes a query resultset cache that works in tandem with the second-level cache.
Question 2: Is the SessionFactory object thread-safe?
- No
- Yes (Correct answer)
Correct answer: Yes
Explanation: <br> Yes, SessionFactory is thread-safe, and numerous threads can access it at the same time.
Question 3: What is the meaning of lazy loading?
- Lazy loading is a technique in which objects are persisted on demand basis
- Lazy loading is a technique in which objects are loaded on demand basis (Correct answer)
- Both of the above
- None of the above
Correct answer: Lazy loading is a technique in which objects are loaded on demand basis
Explanation: <br> The term "lazy loading" refers to a strategy in which objects are loaded only when they are needed.
Question 4: In the hibernate configuration, which of the following statements concerning the hibernate.dialect property is true?
- This property makes HIbernate generate the appropriate Java code for the course chosen database
- This property makes Hibernate generate the appropriate java code for the course chosen database (Correct answer)
- Both of the above
- None of the above
Correct answer: This property makes Hibernate generate the appropriate java code for the course chosen database
Explanation: <br> Hibernate generates the necessary SQL for the selected database when this property is set.
Question 5: Which of the following statements concerning Hibernate's Query object is correct?
- A Query instance is used to bind query parameters, limit the number of results returned by a query, and then execute the query.
- To retrieve data from the database and construct objects, use the Hibernate Query Language (HQL) string.
- To retrieve data from the database and construct objects, use the query objects SQL string.
- All of the above (Correct answer)
Correct answer: All of the above
Explanation: <br> Query objects retrieve data from the database and construct objects using SQL or Hibernate Query Language (HQL) strings. A Query instance is used to bind query parameters, limit the number of results returned by a query, and then execute the query.
Question 6: What is the difference between the session object's save() and persist() methods?
- save saves the object and returns status whereas persist store status in different
- save saves the object and returns the id of the instance whereas peresist do not return anything after saving the instance (Correct answer)
- There is no difference
- None of these
Correct answer: save saves the object and returns the id of the instance whereas peresist do not return anything after saving the instance
Explanation: <br> Persist does not return anything after saving the instance, whereas save saves the object and returns the instance's id.
Question 7: Which of the following statements concerning the @Id annotation is correct?
- Hibernate assumes that it should access properties on an object directly through fields at runtime
- Hibernate detects that the @ld annotation is on a field
- Both of the above (Correct answer)
- None ot these
Correct answer: Both of the above
Explanation: <br> Hibernate recognizes the @Id annotation on a field and thinks that during runtime, it should be able to access attributes on an object directly through fields.
Question 8: Which of the following statements about ORM vs. JDBC is correct?
- ORM system helps in Transaction management and automatic key generation
- ORM system lets business code a access objects rather than DB tables
- ORM system hides details of SQL queries from OO logic
- All of these (Correct answer)
Correct answer: All of these
Explanation: <br> When it comes to ORM vs JDBC, all of the above is true.
Question 9: When should you utilize a read-only concurrency strategy?
- Use this strategy for read-mostly data where it is critical to prevent stale data in concurrent transactions
- Use this method if data is rarely updated and a slight chance of stale data isn't a major concern. (Correct answer)
- Use it for reference data only
- None of the above
Correct answer: Use this method if data is rarely updated and a slight chance of stale data isn't a major concern.
Explanation: <br> The read-only concurrency method is appropriate for data that does not change. It should only be used as a source of information.
In Hibernate, what is Query Level Cache?