250+ TOP MCQs on ORM Frameworks and Answers

Java Spring Multiple Choice Questions & Answers (MCQs) on “ORM Frameworks”.

1. Class which represents a real-world entity and its instances will be persisted to a database.
a) entity
b) persistent
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: Class is called an entity class or a persistent class because it represents a real-world entity and its instances will be persisted to a database.

2. Each entity class to be persisted by an ORM framework, a default constructor with no argument is required.
a) True
b) False
Answer: a
Clarification: For each entity class, you must define an identifier property to uniquely identify an entity.

3. If the identifier value is null, this entity will be treated as a new and unsaved entity.
a) True
b) False
Answer: a
Clarification: When this entity is persisted, an insert SQL statement will be issued; otherwise, an update statement will.

4. To allow the identifier to be null, you should choose a primitive wrapper type:-
a) java.lang.Integer
b) java.lang.Long
c) all of the mentioned
d) none of the mentioned
Answer: c
Clarification: To allow the identifier to be null, you should choose a primitive wrapper type like java.lang.Integer and java.lang.Long for the identifier.

5. A set of persistent annotations for you to define mapping metadata.
a) JPA
b) JSR
c) XML
d) None of the mentioned
Answer: a
Clarification: JPA defines a set of persistent annotations for you to define mapping metadata in a standard format that is more likely to be reusable in other ORM frameworks.

6. For mapping and persisting your objects with Hibernate and JPA.
a) Using the Hibernate API to persist objects with Hibernate XML mappings
b) Using the Hibernate API to persist objects with JPA annotations
c) Using JPA to persist objects with JPA annotations
d) All of the mentioned
Answer: d
Clarification: Hibernate also supports the use of JPA annotations to define mapping metadata, so there are
essentially three different strategies for mapping and persisting your objects with Hibernate and JPA:
• Using the Hibernate API to persist objects with Hibernate XML mappings
• Using the Hibernate API to persist objects with JPA annotations
• Using JPA to persist objects with JPA annotations

7. Core Programming Elements for Different Data Access Strategies.
a) Resource
b) Resource Factory
c) Session
d) All of the mentioned
Answer: d
Clarification: Core Programming Elements for Different Data Access Strategies
Concept JDBC Hibernate JPA
Resource Connection Session EntityManager
Resource factory DataSource SessionFactory EntityManagerFactory
Exception SQLException HibernateException PersistenceException

8. Interface whose instances can be obtained from a SessionFactory instance.
a) Session
b) Session Factory
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: In Hibernate, the core interface for object persistence is Session, whose instances can be obtained from a SessionFactory instance.

9. Interface whose instances can be obtained from an EntityManagerFactory instance.
a) Entity
b) EntityManager
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: In JPA, the corresponding interface is EntityManager, whose instances can be obtained from an EntityManagerFactory instance.

10. The exceptions thrown by Hibernate are of type HibernateException, while those thrown by JPA may be of type PersistenceException.
a) True
b) False
Answer: a
Clarification: Other Java SE exceptions like IllegalArgumentException and IllegalStateException.

11. To accept a session factory via dependency injection.
a) HibernateCourseDao
b) HibernateCourse
c) HibernateDao
d) All of the mentioned
Answer: a
Clarification: Modify HibernateCourseDao to accept a session factory via dependency injection, instead of creating it directly with the native Hibernate API in the constructor.

12. Property for factory bean to load the Hibernate configuration file.
a) config.xml
b) config
c) configLocation
d) none of the mentioned
Answer: c
Clarification: The configLocation property is of type Resource, but you can assign a string value to it.

13. If you want to use this data source for your session factory, you can inject it into the dataSource property of LocalSessionFactoryBean.
a) True
b) False
Answer: a
Clarification: The data source specified in this property will override the database settings in the Hibernate configuration file.

14. FactoryBean to create an entity manager factory in the IoC container.
a) LocalEntityManagerFactoryBean
b) LocalEntityManagerFactory
c) LocalEntityManager
d) All of the mentioned
Answer: a
Clarification: Spring provides a factory bean, LocalEntityManagerFactoryBean, for you to create an entity manager factory in the IoC container.

15. It allows you to override some of the configurations in the JPA configuration file.
a) LocalEntityManagerFactoryBean
b) LocalContainerEntityManagerFactoryBean
c) All of the mentioned
d) None of the mentioned
Answer: b
Clarification: Spring supports a more flexible way to create an entity manager factory by another factory bean, LocalContainerEntityManagerFactoryBean. It allows you to override some of the configurations in the JPA configuration file, such as the data source and database dialect.

Leave a Reply

Your email address will not be published. Required fields are marked *