- Hibernate Tutorial
- Hibernate - Home
- ORM - Overview
- Hibernate - Overview
- Hibernate - Architecture
- Hibernate - Environment
- Hibernate - Configuration
- Hibernate - Sessions
- Hibernate - Persistent Class
- Hibernate - Mapping Files
- Hibernate - Mapping Types
- Hibernate - Examples
- Hibernate - O/R Mappings
- Hibernate - Annotations
- Hibernate - Query Language
- Hibernate - Criteria Queries
- Hibernate - Native SQL
- Hibernate - Caching
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate Useful Resources
- Hibernate - Questions and Answers
- Hibernate - Quick Guide
- Hibernate - Useful Resources
- Hibernate - Discussion
Hibernate Mock Test
This section presents you various set of Mock Tests related to Hibernate Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
Hibernate Mock Test II
Q 1 - Session.createCriteria creates a new Criteria instance, for the given entity class, or a superclass of an entity class.
Answer : A
Explaination
Session.createCriteria creates a new Criteria instance, for the given entity class, or a superclass of an entity class.
Q 2 - Session.createQuery creates a new instance of Query for the given HQL query string.
Answer : A
Explaination
Session.createQuery creates a new instance of Query for the given HQL query string.
Q 3 - Session.createSQLQuery creates a new instance of Query for the given HQL query string.
Answer : B
Explaination
Session.createSQLQuery creates a new instance of Query for the given SQL query string.
Q 4 - Session.createSQLQuery creates a new instance of Query for the given SQL query string.
Answer : A
Explaination
Session.createSQLQuery creates a new instance of Query for the given SQL query string.
Q 5 - Which method is used to remove a persistent instance from the datastore?
Answer : A
Explaination
Session.delete() removes a persistent instance from the datastore.
Q 6 - Which method is used to get a persistent instance from the datastore?
Answer : B
Explaination
Session.get returns the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.
Q 7 - Which method is used to re-read the state of the given instance from the underlying database?
Answer : A
Explaination
Session.refresh re-reads the state of the given instance from the underlying database.
Q 8 - Which method is used to save the state of the given instance from the underlying database?
Answer : C
Explaination
Session.save saves the state of the given instance from the underlying database.
Q 9 - Which method is used to update the state of the given instance from the underlying database?
Answer : C
Explaination
Session.update updates the state of the given instance from the underlying database.
Q 10 - Which method is used to save or update the state of the given instance from the underlying database?
Answer : A
Explaination
Session.saveOrUpdate either saves(Object) or updates(Object) the given instance.
Q 11 - Which of the following is the root node of hbm.xml file?
Answer : A
Explaination
The mapping document is an XML document having <b><hibernate-mapping></b> as the root element which contains all the <class> elements.
Q 12 - Which of the following elements is used to define specific mappings from a Java classes to the database tables?
Answer : C
Explaination
The <class> elements are used to define specific mappings from a Java classes to the database tables. The Java class name is specified using the name attribute of the class element and the database table name is specified using the table attribute.
Q 13 - Which of the following is true about <class> element?
B - The Java class name is specified using the name attribute of the class element.
C - The database table name is specified using the table attribute of the class element.
Answer : D
Explaination
The <class> elements are used to define specific mappings from a Java classes to the database tables. The Java class name is specified using the name attribute of the class element and the database table name is specified using the table attribute.
Q 14 - Which element of hbm.xml defines maps the unique ID attribute in class to the primary key of the database table?
Answer : A
Explaination
The <id> element maps the unique ID attribute in class to the primary key of the database table.
Q 15 - Which of the following is true about <id> element?
A - The <id> element maps the unique ID attribute in class to the primary key of the database table.
B - The name attribute of the id element refers to the property in the class.
C - The column attribute of the id element refers to the column in the database table.
Answer : D
Explaination
The <id> element maps the unique ID attribute in class to the primary key of the database table. The name attribute of the id element refers to the property in the class and the column attribute refers to the column in the database table. The type attribute holds the hibernate mapping type, this mapping types will convert from Java to SQL data type.
Q 16 - Which element of hbm.xml automatically generate the primary key values?
Answer : B
Explaination
The <generator> element within the id element is used to automatically generate the primary key values.
Q 17 - Which of the following is true about <generator> element?
Answer : C
Explaination
The <generator> element within the id element is used to automatically generate the primary key values. Set the class attribute of the generator element is set to native to let hibernate pick up either identity, sequence or hilo algorithm to create primary key depending upon the capabilities of the underlying database.
Q 18 - Which element of hbm.xml is used to map a Java class property to a column in the database table?
Answer : C
Explaination
The <property> element is used to map a Java class property to a column in the database table.
Q 19 - Which of the following is true about <property> element?
A - The <property> element is used to map a Java class property to a column in the database table.
B - The name attribute of the element refers to the property in the class.
C - The column attribute of the element refers to the column in the database table.
Answer : D
Explaination
The <property> element is used to map a Java class property to a column in the database table. The name attribute of the element refers to the property in the class and the column attribute refers to the column in the database table. The type attribute holds the hibernate mapping type, this mapping types will convert from Java to SQL data type.
Q 20 - Which of the following element maps java.util.Set property in hibernate?
Answer : A
Explaination
java.util.Set property is mapped with a <set> element and initialized with java.util.HashSet.
Q 21 - Which of the following element maps java.util.List property in hibernate?
Answer : B
Explaination
java.util.List property is mapped with a <list> element and initialized with java.util.ArrayList.
Q 22 - Which of the following element maps java.util.Collection property in hibernate?
Answer : C
Explaination
java.util.Collection property is mapped with a <bag> or <ibag> element and initialized with java.util.ArrayList.
Q 23 - Which of the following element maps java.util.Map property in hibernate?
Answer : D
Explaination
java.util.Map property is mapped with a <map> element and initialized with java.util.HashMap.
Q 24 - Which of the following element maps java.util.SortedMap property in hibernate?
Answer : D
Explaination
This is mapped with a <map> element and initialized with java.util.TreeMap. The sort attribute can be set to either a comparator or natural ordering.
Q 25 - Which of the following element is used to represent many-to-one relationship in hibernate?
Answer : A
Explaination
<many-to-one> element is used to define many-to-one association.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | A |
2 | A |
3 | B |
4 | A |
5 | A |
6 | B |
7 | A |
8 | C |
9 | C |
10 | A |
11 | A |
12 | C |
13 | D |
14 | A |
15 | D |
16 | B |
17 | C |
18 | C |
19 | D |
20 | A |
21 | B |
22 | C |
23 | D |
24 | D |
25 | A |