Spring Data JDBC and JPA
Learn about a few interview questions regarding Spring data JDBC and JPA.
How does Spring provide DAO support?
Spring DAO support makes it easy to work with different data access technologies in a consistent way which makes it easy to switch between technologies like JDBC, Hibernate, or JDO. Main features of Spring DAO support are:
- Exception handling: Technology specific exception like
SQLException
is translated to Spring’sDataAccessException
. Checked exceptions in Hibernate, JPA, and JDO can be converted to runtime exceptions. - Abstract DAO support classes: Spring provides abstract classes for different data access technologies which provide methods for data source and other configuration settings. These include the
JdbcDaoSupport
,HibernateDaoSupport
,JdoDaoSupport
, andJpaDaoSupport
classes.
Describe Spring DAO support classes.
Spring provides technology specific abstract classes for DAO support. These classes have methods for providing data source and other configuration settings specific to the data access technology. Abstract DAO support classes are:
JdbcDaoSupport
class requiresDataSource
and returnsJdbcTemplate
instance.HibernateDaoSupport
class requiresSessionFactory
and returnsHibernateTemplate
instance.JdoDaoSupport
class requiresPersistenceManagerFactory
and returnsJdoTemplate
instance.JpaDaoSupport
class requiresEntityManagerFactory
and returnsJpaTemplate
instance.
What annotation is used to mark DAO in Spring?
The @Repository
annotation is used for DAO classes. This annotation provides the Spring exception translation facility which converts a technology specific expectation to a DataAccessException
.
What is Spring data JDBC?
Spring Data JDBC framework is part of Spring Data. It provides support for JDBC repositories. Spring Data JDBC is a simple but limited ORM. It does not implement features like caching, lazy loading, and write-behind. Unlike Spring Data JPA, it does not provide schema generation and the developer must explicitly create the schema.
Spring JDBC uses methods like ...