Hibernate Questions

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Kushin
K
Kushin
Community Contributor
Quizzes Created: 1 | Total Attempts: 3,831
Questions: 10 | Attempts: 3,831

SettingsSettingsSettings
Hibernate Quizzes & Trivia

This is hibernate quiz


Questions and Answers
  • 1. 

    Which of the following are most common configuration methods of Hibernate Configuation

    • A.

      Mapping files

    • B.

      Http.conf

    • C.

      XML Configuration hibernate.cfg.xml

    • D.

      Web.config

    Correct Answer(s)
    A. Mapping files
    C. XML Configuration hibernate.cfg.xml
    Explanation
    The most common configuration methods of Hibernate Configuration are mapping files and XML Configuration hibernate.cfg.xml. Mapping files are used to define the mapping between Java objects and database tables, while hibernate.cfg.xml is an XML configuration file that contains various settings and properties for Hibernate.

    Rate this question:

  • 2. 

    Which of the following is FALSE about Session in hibernate

    • A.

      Session is a light weight non-threadsafe object

    • B.

      You can share the session between threads

    • C.

      Session represents a single unit-of-work with the database

    • D.

      Session is the primary interface for the persistence service

    • E.

      A session loads database connections using lazy-loading

    Correct Answer
    B. You can share the session between threads
    Explanation
    The statement "You can share the session between threads" is FALSE. In Hibernate, a Session is not designed to be shared between multiple threads. It is a light weight non-threadsafe object that represents a single unit-of-work with the database. Each thread should have its own Session object to ensure thread safety and avoid potential issues with concurrent access to the database. Sharing a Session between threads can lead to unpredictable behavior and data integrity problems.

    Rate this question:

  • 3. 

    __________ objects can be passed across layers all the way up to the presentation layer without having to use any DTOs (Data Transfer Objects). You can later re-attach them to another session

    Correct Answer
    detached
    Detached
    Explanation
    Detached objects can be passed across layers all the way up to the presentation layer without having to use any DTOs. These objects are not associated with any particular session and can be re-attached to another session later. This allows for more efficient and streamlined communication between different layers of an application, as there is no need to convert the data into DTOs for transfer.

    Rate this question:

  • 4. 

    Which of the following are tags of hibernate.cfg.xml? Select all that apply

    • A.

      DTD

    • B.

      JDBC connection

    • C.

      SQL variant to generate

    • D.

      Mapping files

    • E.

      Size of the database

    Correct Answer(s)
    A. DTD
    B. JDBC connection
    C. SQL variant to generate
    D. Mapping files
    Explanation
    The hibernate.cfg.xml file is used to configure Hibernate in a Java application. It includes various tags that define the settings and properties for Hibernate. The DTD tag is used to specify the Document Type Definition for the XML file. The JDBC connection tag is used to define the database connection details. The SQL variant to generate tag is used to specify the type of SQL syntax to be generated by Hibernate. The Mapping files tag is used to specify the mapping files that define the object-relational mapping for the application. The Size of the database tag is not a valid tag for hibernate.cfg.xml, so it is not included in the correct answer.

    Rate this question:

  • 5. 

    There are core interfaces are used in just about every Hibernate application. Using these interfaces, you can store and retrieve persistent objects and control transactions. Select all the interfaces that you see

    • A.

      Configuration interface

    • B.

      Session interface

    • C.

      Query and Criteria interfaces

    • D.

      User Interface

    • E.

      Configuration interface

    Correct Answer(s)
    A. Configuration interface
    B. Session interface
    C. Query and Criteria interfaces
    E. Configuration interface
    Explanation
    The given correct answer is Configuration interface, Session interface, Query and Criteria interfaces. These interfaces are commonly used in Hibernate applications. The Configuration interface is used to configure Hibernate and provide necessary information for the SessionFactory. The Session interface represents a single unit of work and is used to perform database operations. The Query and Criteria interfaces are used for querying the database and retrieving data. Therefore, these interfaces are essential in Hibernate applications for managing persistent objects and controlling transactions.

    Rate this question:

  • 6. 

    Which of the following is NOT a role of the session interface? Select only ONE

    • A.

      Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier

    • B.

      Created during application initialization

    • C.

      Wraps a JDBC connection

    • D.

      Act as Factory for Transaction

    Correct Answer(s)
    A. Holds a mandatory (first-level) cache of persistent objects, used when navigating the object grapH or looking up objects by identifier
    C. Wraps a JDBC connection
    D. Act as Factory for Transaction
    Explanation
    The session interface does not hold a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier. It does, however, have the roles of being created during application initialization, wrapping a JDBC connection, and acting as a factory for transactions.

    Rate this question:

  • 7. 

    Which of the following is NOT a step in the Hibernate communication with RDBMS? Select ALL than Apply (only one doesnt )

    • A.

      Create HQL Query

    • B.

      Execute query to get list containing Java objects

    • C.

      Create session from configuration object

    • D.

      Load the Hibernate configuration file and create configuration object

    • E.

      Get one session from the session factory

    Correct Answer(s)
    A. Create HQL Query
    B. Execute query to get list containing Java objects
    D. Load the Hibernate configuration file and create configuration object
    E. Get one session from the session factory
    Explanation
    The correct answer is "Create HQL Query, Execute query to get list containing Java objects, Load the Hibernate configuration file and create configuration object, Get one session from the session factory." These are all steps in the Hibernate communication with RDBMS. The incorrect answer would be "Create session from configuration object" as this is a step in the Hibernate communication with RDBMS.

    Rate this question:

  • 8. 

    Which of the following is not a Session method? Select ONE

    • A.

      Session.save()

    • B.

      Session.remove()

    • C.

      Session.saveorupdate()

    • D.

      Session.persist()

    • E.

      Session.load()

    Correct Answer
    B. Session.remove()
    Explanation
    The method Session.remove() is not a valid Session method because there is no such method in the Session class. The other options, Session.save(), Session.saveorupdate(), Session.persist(), and Session.load() are all valid Session methods that are used for various operations such as saving or updating an object, persisting an object, and loading an object respectively.

    Rate this question:

  • 9. 

    What is the method name Session.____() that would re-load an object and all its collections

    Correct Answer
    refresh
    Refresh
    Explanation
    The method name "refresh" or "Refresh" is used to reload an object and all its collections. This method is commonly used in programming to retrieve the latest data from a database or to update the state of an object with the most recent information. By calling this method, the object and its associated collections are refreshed and any changes made since the last retrieval or update are reflected.

    Rate this question:

  • 10. 

    Which of the following is NOT a best practice for defining your Hibernate persistent classes?

    • A.

      You must have a default no-argument constructor for your persistent classes and there should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for all your persistable instance variables.

    • B.

      You should implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is because the Hibernate only generates and sets the field when saving the object.

    • C.

      It is recommended to implement the Serializable interface. This is potentially useful if you want to migrate around a multi-processor cluster.

    • D.

      The persistent class should be final because if it is final then lazy loading can be used by creating proxy objects.

    Correct Answer(s)
    A. You must have a default no-argument constructor for your persistent classes and there should be getXXX() (i.e accessor/getter) and setXXX( i.e. mutator/setter) methods for all your persistable instance variables.
    B. You should implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key (i.e. Hibernate managed identifier). This is because the Hibernate only generates and sets the field when saving the object.
    C. It is recommended to implement the Serializable interface. This is potentially useful if you want to migrate around a multi-processor cluster.
    Explanation
    The given answer states that a best practice for defining Hibernate persistent classes is to have a default no-argument constructor and accessor/getter and mutator/setter methods for all persistable instance variables. It also recommends implementing the equals() and hashCode() methods based on the business key, without using the id field if it is a surrogate key. Additionally, it suggests implementing the Serializable interface for potential use in migrating around a multi-processor cluster. However, the answer does not mention that the persistent class should be final in order to use lazy loading with proxy objects.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 18, 2009
    Quiz Created by
    Kushin

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.