Our experts have gathered these Hibernate MCQs through research, and we hope that you will be able to see how much knowledge base you have for the subject of Hibernate by answering these 100+ multiple-choice questions.
Get started now by scrolling down!
A. Jeremy Does Backflips Consistently
B. Java Does Best Connection
C. Java DataBase Connection
D. Just Do Both Carefully
A. A single-threaded, short-lived object representing a conversation between the application and the persistent store
B. Short-lived, single threaded objects containing persistent state and business function
C. Instances of persistent classes that are not currently associated with a org.hibernate.Session
D. A thread-safe, immutable cache of compiled mappings for a single database
A. The identifier property (if it exists) is null
B. All of these
C. You supply an unsaved-value in the mapping document for the class, and the value of the identifier property matches
D. The version property (if it exists) is null
A. The first level caching is provided by the EntityManager
B. The first level caching is limited to a particular user or request
C. Hibernate provides 2 levels of caching
D. All of these
A. <hibernate-hibernate>
B. <hibernate-java-java>
C. <hibernate-mapping>
D. <hibernate-tabular>
A. modular
B. open
C. ORM
D. OS
A. Session.Cloak()
B. Session.Close();
C. Session.Close
D. Session.Cloak
A. The API mismatch
B. The structural mismatch
C. The duplication mismatch
D. All
A. MXL
B. LMX
C. XXML
D. XML
A. A variable
B. The Declare statement
C. xpath mapping file
D. XML mapping file
A. client
B. tough
C. javascript
D. Object-Oriented
A. object redundant marker
B. object real maker
C. object relational marker
D. object relational mapping
A. zip it up
B. backflip
C. rollback
D. fallback
A. stores
B. tabs
C. non-persists
D. grows
A. vbscript
B. javascript
C. SQL
D. perl
A. delayed
B. self-orienting
C. thread safe
D. lousy
A. Hibernate Search works well in clustered mode
B. Hibernate Search provides synchronous and asynchronous index updates
C. Hibernate Search works well in non-clustered mode
D. All
A. Specifying queries that refer to classes and properties of classes
B. Performing basic CRUD operations on objects of persistent classes
C. All of these
D. Specifying mapping metadata
A. rational database
B. revised database
C. relational database
D. redundant database
A. HQL
B. C#
C. .Net
D. Java
A. xpath
B. XML
C. PL-SQL
D. XSLY
A. Plain Ole Java Object
B. Plain Old Java Object
C. Plaine Ole Java Object
D. Plaine Old Java Object
A. tabular
B. delimited
C. reformatted
D. delayed
A. sproc
B. UDF
C. transaction
D. table
A. browser
B. javascript
C. JAR
D. XML
A. Its is used to specify the table to persist the data
B. It is used to mark this class as an Entity bean
C. It is used to specify the identifier property of the entity bean
D. It is used to specify the primary key generation strategy
A. Variable
B. OOP
C. SQL
D. Integer
A. SessionFactory
B. Rational Database
C. ArrayList
D. VariableRepository
A. add @Fetch annotation and specify a FetchMode of JOIN
B. add @Fetch annotation and specify a FetchMode of SUBSELECT
C. use LEFT JOIN FETH clause on the HQL
D. All of these
A. <HTML>
B. <JAVA>
C. <property>
D. <XML>
A. Facilitates auditing of Hibernate mappings, which extend JPA, like custom types and collections/maps of "simple" types (Strings, Integers, etc.)
B. Facilitates auditing of all mappings defined by the JPA specification
C. Facilitates querying historical data
D. All
A. Both database connection and class mapping setup
B. Class mapping setup but NOT database connection
C. Database connection but NOT class mapping setup
D. SessionFactory but NEITHER database connection NOR class mapping setup
A. dialect
B. session
C. transaction
D. driver_class
A. transactionManager
B. hibernate-configuration
C. sessionFactory
D. cache.provider_class
A. Session-scoped
B. Session-scoped but NOT SessionFactory-scoped
C. Both Session-scoped and SessionFactory-scoped
D. SessionFactory-scoped
A. All
B. javax.persistence.metamodel.Metamodel acts as a repository of metamodel objects and provides access to them
C. Handle to javax.persistence.metamodel.Metamodel can be obtained from either the javax.persistence.EntityManagerFactory or the javax.persistence.EntityManagervia their getMetamodel method
D. The metamodel is a set of objects that describe a domain model
A. An instance will be detached after it gets retrieved from the database by the execution of query.
B. Changes made to the detached instance are still guaranteed to synchronize with the database.
C. A persistent instance will become detached after the session is closed.
D. Hibernate does NOT allow you to re-associate detached instances with a new persistence manager.
A. You can use SessionFactory to create Session instance
B. SessionFactory is not lightweight and is expensive to create
C. One SessionFactory can manage more than one database
D. The SessionFactory caches generated SQL statements and other mapping meta data that Hibernate uses at runtime
A. <property>
B. <session-factory>
C. <mapping>
D. <hibernate-configuration>
A. Transaction
B. Session
C. TransactionFactory
D. ConnectionProvider
A. validate
B. truncate
C. create
D. update
A. Detached instants can be made persistent by calling saveOrUpdate()
B. Transient instants can be made persistent by calling delete()
C. Transient instants are previously persistent and associated with an unique session
D. Persistent instants can be made transient by calling update()
A. You can use asc and desc to specify ascending and descending order
B. You cannot order query results by more than one properties
C. The default ordering is ascending
D. HQL provides an ORDER BY clause for ordering query result
A. The named query must be HQL strings. Native SQL is not supported in named query
B. The getNamedQuery() method obtains a query instance of named query
C. Named queries are precompiled when session factory is created
D. Named queries allow externalizing query strings to the mapping metadata
A. First Level Cache
B. Application layer level cache
C. Transaction layer level cache
D. SQL cache
A. ORM
B. JDBC
C. JMS
D. JPA
A. Multiple instances of SessionFactory are created, usually on application startup, from a Configuration instance
B. A Session is an inexpensive, non-threadsafe object that should be used once and then discarded for: a single request, a conversation or a single unit of work
C. In order to reduce lock contention in the database, a database transaction has to be as short as possible
D. A SessionFactory is an expensive-to-create, threadsafe object, intended to be shared by all application threads
A. The @Table annotation can be used to specify mapping database schema name
B. The @Column annotations is used to specify the column name of the foreign key
C. The @Entity annotation indicates that the class is mapped to a table in database
D. The @Id annotation indicates the field is the primary key for the entity
A. Configuration
B. Transaction
C. Session
D. SessionFactory
A. If the query returns more than result for the uniqueResult() method, the first one will be returned.
B. Both the createQuery() and createSQLQuery() method of Session interface can return a Query instance
C. You can paging the query result by using setFirstResult() and setMaxResult() method
D. You can use method chaining (methods return receiving object instead of void) with Query interface
A. You can use = NULL to test whether the value is null
B. The HQL where clause supports arithmetic expressions
C. The where clause is a logical expression evaluating to true false or null
D. The "like" operator allows wildcard(%) searches
A. Hibernate flushes by default before some queries
B. Hibernate flushes by default when session.flush() is executed
C. Hibernate flushes by default when commit() is executed
D. Hibernate NEVER flushes by default
A. A sorted collection is sorted in-memory using java comparator, while order collection is ordered at the database level using order by clause
B. An order collection is sorted in-memory using java comparator, while sorted collection is ordered at the database level using order by clause
C. A sorted collection is either sorted in-memory using java comparator or using order by clause at the database level
D. An order collection is either sorted in-memory using java comparator or using order by clause at the database level
A. OPTIMISTIC_FORCE_INCREMENT
B. UPDATE
C. PESSIMISTIC_FORCE_INCREMENT
D. OPTIMISTIC
A. Session is Hibernate's interface for persistence-related operations such as storing and retrieving objects
B. An instance of Session is lightweight and is inexpensive to create and destroy.
C. Hibernate session has nothing to do with the web-tier HttpSession.
D. Hibernate can detect changes to the objects and make updates to the database automatically even if changes are made within the same session.
A. The load() method and get() method of Session interface are same
B. The load() method can return a poxy than immediately hitting the database.
C. The load() method of Session interface will return null if no row find in the database
D. The get() method of Session interface will throw exception if no row find in the database
A. The as keyword is optional
B. The query indicates that there is a table named item and has columns named as "description" and "date"
C. The index of binding parameter start from 1 instead of 0
D. The FROM WHERE AND are HQL keywords and has to be uppercase
A. log4j
B. JCL
C. Simple Logging Facade for Java (SLF4J)
D. JDK logging
A. files
B. data
C. databases
D. navigation
A. The @AttributeOverride annotation defines what type the database uses to save the embeddable field
B. The @Embedded annotation means the annotated field is embeddable type
C. User @Emebeddable on a class means it's fields and properties will be persistable as part of another entity.
D. The Embeddable type can be reused on other types
A. Hibernate uses this cache by default
B. It loads objects and make them available to the entire application
C. it reduces the number of generated SQL queries within a given transaction
D. It always "associates" with the Session object
A. Read-only
B. Write-only
C. Nonstrict read/write
D. Read/write
A. You cannot retrieve objects using native SQL queries in Hibernate
B. HQL Hibernate Query Language is a full object oriented query language
C. When you're using get() method to retrieve an object that doesn't exist in the database, Hibernate will throw an exception
D. When you using load() method to retrieve an object that doesn't exist in the database, Hibernate will return null
A. delimited
B. tabular
C. array
D. graph
A. If the timestamp of the most recent update made to the queried table is early than the timestamp of the cached query results, then the cached results are discarded
B. UpdateTimestampsCache is a special cache region that holds timestamps of the most recent updates to each table
C. The query cache must be enabled using a Hibernate property setting:hibernate.cache.use_query_cache true
D. Hibernate allows you to specify a different named cache region for each query
A. The many to may relationship can be both unidirectional or bidirectional
B. mappedBy element must be included for the bidirectional many to many relationship
C. The @JoinColumn and @InverseJoinColumns are used to defined the column names of the foreign keys in the join table
D. The @JoinTable annotation must be defined on the reverse side of the many to many relation ship
A. Hibernate component is the lowest level of unit and cannot own other component
B. We can declare a component of an entity by using <component> element
C. Component is the user defined class that is persisted to the table of owning entity
D. Hibernate support both unidirectional and bidirectional composition
A. It is a persistence engine providing Java Persistence (JPA) support for NoSQL storage solutions
B. It is expected to be used to interact with all NoSQL solution in all use cases
C. It reuses Hibernate Core's object life cycle management and (de)hydration engine but persists entities into a key/value store instead of a relational database
D. It reuses the Java Persistence Query Language (JP-QL) as an interface to querying stored data
A. cascade ="delete" tells Hibernate to navigate the association when performing delete
B. cascade="all-delete-orphan" is the same as cascade="all" in addition it deletes any persistent instant when it get dereferenced
C. cascade="save-update" is the default setup in hibernate
D. cascade ="none" tells hibernate to ignore association
A. The default value of discriminatorType element in @DiscriminatorColumn is DiscriminatorType.INTEGER
B. the @Inheritance annotation is used on the subclass to setup the inheritance mapping strategy
C. the @DiscriminatorValue annotation is used to specify the value in the in the discriminator column in database
D. the name element of @DiscriminatorColumn annotation specify the name of table
A. Caching query will have more impact on applications that perform many inserts, deletes or updates.
B. The iterate()method of the Session and Query interfaces is provided to take advantage of second-level cache.
C. The query cache cache all the entities properties returned in the query result set
D. To enable query cache all it needs is to invoke setCacheable(true) on the query instance.
A. Path navigation from one entity is a form of outer join.
B. Join conditions can be specified explicitly by using the 'join' keyword
C. An inner join between two entities returns the objects from both entity types that satisfy all the join conditions
D. Join conditions can be specified implicitly as a result of path navigation.
A. It is called 'second-level' because there is already a cache operating in Hibernate for the duration of an open session
B. It always "associates" with the Session Factory object
C. It exists as long as the session factory is alive
D. By default it effectively holds on to the identifiers for an individual query
A. entities may be mapped across multiple tables by making use of the @SecondaryTables annotation
B. The "table" attribute needs to be defined in the @Column annotation to specify which table the column belongs
C. The @PrimaryKeyJoinColumn annotation specifies the primary key of the primary table
D. entities may be mapped across multiple tables by making use of the @SecondaryTable annotation
A. It represents the absence of a lock
B. All objects switch to this lock mode at the end of a Transaction
C. Objects associated with the session via a call to update() or saveOrUpdate() also start out in this lock mode
D. If an object is requested with this lock mode, a WRITE lock will be obtained if it is necessary to actually read the state from the database
A. The @Inheritance annotation has a "strategy" attribute which can be used to define the inheritance mapping strategy
B. The @DiscriminatorColumn is used to defined the named of the column that is used to differentiate subclasses
C. The root class of the hierarchy needs to be marked by the @Inheritance annotation
D. The @DiscriminatorValue doesn't have default value and must be defined.
A. The load() method returns null, when the unique id could not found in the database
B. The load() method returns proxy by default and the data base will not be effected until the invocation of the proxy
C. The load() method throws an exception,when the unique id could not found in the database
D. The get() method returns null when the unique id is unavailable in the database.
A. Log all SQL DDL statements as they are executed
B. Log all SQL DML statements as they are executed
C. Log all JDBC parameters
D. Log the state of all entities
A. It is more is expensive to query subclass when using join strategy
B. Join strategy is the most efficient way to insert data
C. Join strategy is the most efficient way to store data
D. In join strategy every class will have its state mapped to a different table
A. Firing of a PostPersist event does not indicate that the entity has committed successfully to the database
B. If the PERSIST cascade option is set on a relationship of an object that is being persisted and the target object is also a new object, the PrePersist event is triggered on the target object.
C. The PostLoad callback occurs after the data for an entity is read from the database and the entity instance is constructed.
D. When the SQL for deletion of an entity gets sent to the database, the PostRemove event will get fired and it indicates success of deletion
A. hilo
B. primary
C. identity
D. sequence
A. The query returns a List of Object[] arrays
B. The query assigns the alias "item" to the class ITEM and alias "bid" to the Bid class
C. The query returns all combinations of associated Bids and Items
D. The bids collection of each Item will be eagerly loaded.
A. An object of value type always has a primary key value in the database
B. Value type objects belongs to an entity and is embedded in the table row of owning entity
C. An object of Entity type does NOT have its own database identity
D. An Entity type object cannot exist independently and has to bond to another object
A. the Item indicates the name of the entity class and it's case sensitive
B. The query is using native SQL syntax
C. the letter I is alias and the "as" keyword must be place in front of the alias
D. this query is using positional parameter binding
A. The @JoinColumn must be defined with @OneToMany annotation
B. The @JoinColumn defines the name of the foreign column
C. If the relationship is bidirectional mappedBy attribute must be defined for the @OneToMany annotation
D. The @ManyToOne defines a single-valued association to another entity class that has many-to-one multiplicity.
A. objects referred by other transient instances are transient
B. Transient instance is always associated with a row in a database
C. After a persisted instance gets deleted, it'll become a transient instance
D. Objects instantiated using new operator aren't persisted immediately and their state is transient.
A. It does not provide many of the higher-level life cycle semantics
B. A stateless session does not implement a first-level cache
C. A stateless session has no persistence context associated with it
D. Operations performed using a stateless session cascade to associated instances
A. ON_OPEN
B. AFTER_TRANSACTION
C. AFTER_STATEMENT
D. ON_CLOSE
A. The query is using outer join
B. The department objects returned are lazy loaded.
C. The query will return all departments not matter the department has an employee or not
D. The query returns a List of Object[] arrays, at index 0 is Department and Index 1 is Employee
A. Log all first-level cache activity but NOT second-level cache activity
B. Log NEITHER first-level NOR second-level cache activity
C. Log both first-level and second-level cache activity
D. Log all second-level cache activity
A. Neither Merge nor Update
B. Merge
C. Update
D. Both Merge and Update
A. Any change made on the persistent object will be synchronized with the database after the transaction ends.
B. Before session get closed, an object will becomes persistent after it get saved by the persistence manager's save() method.
C. A persistent instance has a primary key set as its database identifier
D. An object is not persistent if it's retrieved from the database by the execution of query.
A. In HQL the LEFT keyword in LEFT JOIN FETCH is optional
B. When using HQL join queries you have to explicitly specify the join condition using either WHERE or ON clause
C. HQL provides a fetch join in the FROM clause to lazy load the associated objects
D. When using outer joins, Hibernate will always return a list containing distinct items.
A. mappedBy element should be specified in the @OneToOne annotation in the entity that defines a join column
B. One to one mapping can only be unidirectional
C. The @JoinColumn annotation goes on the mapping of the entity that is mapped to the table containing the foreign key
D. One to one mapping can only be bidirectional
A. The single table strategy uses one table to contain all the possible state of a hierarchy
B. Single table strategy will be more wasteful of database space.
C. There shouldn't be any columns left unfilled in the single table strategy
D. The single table strategy is the most performance way in polymorphic queries and write operations.
A. Its a Singleton class
B. Its initialization process is expensive as it loads all configurations including database setting, OR settings
C. It helps in customized extraction of data.
D. Configures HIBERNATE with HIBERNATE configuration file for use in application
A. The primary key class needs to be marked with @IdClass annotation
B. The primary key class must be private, but it's optional to implement Serializable
C. Mapping compound primary key requires creating a separate primary key class containing the primary key fields
D. The primary key class must include equals() and hashCode() method
A. The primary goal of Hibernate Shards is to enable application developers to query and transact against sharded datasets using the standard Hibernate Core API
B. Hibernate Shards can be conceptually divided into Generalized sharding logic, Application specific sharding logic and Hibernate Default sharding
C. Hibernate Shards primarily consists of shard-aware implementations of many of the Hibernate Core interfaces
D. Hibernate Shards can be conceptually divided into Generalized sharding logic and Application specific sharding logic
A. This query is using outer join so it'll return all the Phone entity instances no matter it is associated with an Employee or not.
B. This query is missing the joining condition so it won't work
C. The query indicates that the "number" is the name of one of the columns of the Phone table
D. Because the "phones" is a collection association field, the path navigation couldn't continue
A. Session.saveorupdate()
B. Session.remove()
C. Session.save()
D. Session.persist()