Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

What is HibernateTemplate class?

Answer»
  • Prior to Hibernate 3.0.1, Spring provided 2 classes namely: HIBERNATEDAOSUPPORT to get the Session from Hibernate and HibernateTemplate for Spring transaction management purposes.
  • However, from Hibernate 3.0.1 ONWARDS, by using HibernateTemplate class we can use SessionFactory getCurrentSession() METHOD to get the CURRENT session and then use it to get the transaction management benefits.
  • HibernateTemplate has the benefit of EXCEPTION translation but that can be achieved easily by using @Repository annotation with service classes.
2.

What is Hibernate Validator Framework?

Answer»
  • Data VALIDATION is a crucial part of any APPLICATION. We can find data validation in:
    • UI layer before sending objects to the server
    • At the server-side before processing it
    • Before persisting data into the database
  • Validation is a cross-cutting concern/task, so as good PRACTICE, we should try to keep it apart from our business logic. JSR303 and JSR349 PROVIDE specifications for bean validation by using annotations.
  • This framework provides the reference IMPLEMENTATION for JSR303 and JSR349 specifications.
3.

What are the two ways of accessing Hibernate by using Spring.

Answer»
  • Inversion of Control approach by using HIBERNATE Template and Callback.
  • Extending HibernateDAOSupport and Applying an AOP INTERCEPTOR NODE.
4.

What is Hibernate ORM Framework?

Answer»
  • Object-relational MAPPING (ORM) is the PHENOMENON of mapping application domain model OBJECTS to the relational database TABLES and vice versa.
  • Hibernate is the most commonly used java based ORM FRAMEWORK.
5.

How can you fetch records by Spring JdbcTemplate?

Answer»

This can be done by using the QUERY method of JdbcTemplate. There are two interfaces that help to do this:

  • ResultSetExtractor:
    • It defines only ONE method extractData that ACCEPTS ResultSet instance as a parameter and returns the list.
    • Syntax:
public T extractData(ResultSet RS) throws SQLException,DataAccessException;
  • RowMapper:
    • This is an enhanced version of ResultSetExtractor that saves a lot of CODE.
    • It allows to map a row of the relations with the instance of the user-defined class.
    • It iterates the ResultSet internally and adds it into the result collection thereby saving a lot of code to fetch records.
6.

What are some of the classes for Spring JDBC API?

Answer»
  • Following are the classes
    • JdbcTemplate
    • SimpleJdbcTemplate
    • NamedParameterJdbcTemplate
    • SimpleJdbcInsert
    • SimpleJdbcCall
  • The most commonly used one is JdbcTemplate. This internally USES the JDBC API and has the advantage that we don’t need to CREATE connection, statement, START transaction, COMMIT transaction, and close connection to execute different queries. All these are handled by JdbcTemplate itself. The DEVELOPER can focus on executing the query directly.
7.

What is Spring AOP Proxy pattern?

Answer»
  • A proxy pattern is a well-used design pattern where a proxy is an OBJECT that looks like another object but adds special functionality to it behind the scenes.
  • Spring AOP follows proxy-based pattern and this is created by the AOP FRAMEWORK to implement the aspect contracts in runtime.
  • The standard JDK dynamic proxies are default AOP proxies that enables any interface(s) to be proxied. Spring AOP can also use CGLIB proxies that are required to proxy CLASSES, RATHER than interfaces. In case a business object does not implement an interface, then CGLIB proxies are used by default.
8.

What is an advice? Explain its types in spring.

Answer»

An advice is the implementation of cross-cutting CONCERNS can be applied to other modules of the spring application. Advices are of MAINLY 5 types:

  • Before:
    • This advice executes before a join point, but it does not have the ability to prevent execution flow from proceeding to the join point (unless it throws an exception).
    • To use this, use @Before annotation.
  • AfterReturning:
    • This advice is to be executed after a join point COMPLETES normally i.e if a method returns without THROWING an exception.
    • To use this, use @AfterReturning annotation.
  • AfterThrowing:
    • This advice is to be executed if a method exits by throwing an exception.
    • To use this, use @AfterThrowing annotation.
  • After:
    • This advice is to be executed REGARDLESS of the means by which a join point exits (normal return or exception encounter).
    • To use this, use @After annotation.
  • Around:
    • This is the most powerful advice surrounds a join point such as a method invocation.
    • To use this, use @Around annotation.
9.

What is Spring AOP?

Answer»
  • Spring AOP (Aspect Oriented Programming) is similar to OOPs (Object Oriented Programming) as it also provides modularity.
  • In AOP KEY unit is aspects or concerns which are nothing but stand-alone modules in the application. Some aspects have centralized code but other aspects may be scattered or tangled code like in the case of logging or transactions. These scattered aspects are called cross-cutting concern.
    • A cross-cutting concern such as transaction management, authentication, logging, security etc is a concern that could affect the whole application and should be centralized in one LOCATION in code as much as possible for security and modularity purposes.
  • AOP provides platform to dynamically add these cross-cutting concerns before, after or around the actual LOGIC by using simple pluggable configurations.
  • This results in easy maintainenance of code. Concerns can be added or removed simply by modifying configuration files and therefore without the need for recompiling complete sourcecode.
  • There are 2 TYPES of implementing Spring AOP:
    • Using XML configuration files
    • Using AspectJ annotation STYLE