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.

Questions and Answers

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.

A - true

B - false

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.

A - true

B - false

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.

A - true

B - false

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.

A - true

B - false

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?

A - Session.delete()

B - Session.remove()

C - Session.del()

D - Session.rm()

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?

A - Session.read()

B - Session.get()

C - Session.retrieve()

D - Session.fetch()

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?

A - Session.refresh()

B - Session.get()

C - Session.reload()

D - Session.retrieve()

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?

A - Session.store()

B - Session.keep()

C - Session.save()

D - Session.load()

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?

A - Session.store()

B - Session.keep()

C - Session.update()

D - Session.load()

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?

A - Session.saveOrUpdate()

B - Session.keep()

C - Session.update()

D - Session.load()

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?

A - hibernate-mapping

B - hibernate-config

C - class-mapping

D - class-config

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?

A - property

B - hibernate-config

C - class

D - class-config

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.

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?

A - id

B - generator

C - primaryKey

D - None of the above.

Answer : A

Explaination

The <id> element maps the unique ID attribute in class to the primary key of 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?

A - id

B - generator

C - primaryKey

D - None of the above.

Answer : B

Explaination

The <generator> element within the id element is used to automatically generate the primary key values.

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?

A - id

B - generator

C - property

D - class

Answer : C

Explaination

The <property> element is used to map a Java class property to a 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?

A - <set>

B - <list>

C - <bag>

D - <map>

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?

A - <set>

B - <list>

C - <bag>

D - <map>

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?

A - <set>

B - <list>

C - <bag>

D - <map>

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?

A - <set>

B - <list>

C - <bag>

D - <map>

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?

A - <set>

B - <list>

C - <bag>

D - <map>

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?

A - <many-to-one>

B - <many-one>

C - <ManyToOne>

D - None of the above

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
hibernate_questions_answers.htm
Advertisements