Spring Questions and Answers – ORM Frameworks

This set of Java Spring Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: When this entity is persisted, an insert SQL statement will be issued; otherwise, an update statement will.
advertisement
advertisement

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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: d
Explanation: 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
View Answer

Answer: d
Explanation: 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
advertisement

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: In JPA, the corresponding interface is EntityManager, whose instances can be obtained from an EntityManagerFactory instance.
advertisement

10. The exceptions thrown by Hibernate are of type HibernateException, while those thrown by JPA may be of type PersistenceException.
a) True
b) False
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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.

Sanfoundry Global Education & Learning Series – Java Spring.
To practice all areas of Java Spring, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.