May 19 2015

Spring MVC interview questions for experienced

Spring MVC interview questions for experienced

 What is Spring Web MVC framework?

Spring Web MVC is open source web application framework which is part of the Spring framework. Spring Web MVC is one of the efficient and high performance implementation of Model View Controller (MVC) Architecture. Spring MVC provides utility classes to develop web applications.

What is DispatcherServlet?

Spring Web MVC framework is designed around the front controller which is DispatcherServlet. DispatcherServlet listens to the incoming requests and dispatches the request to handler, configurable handler mapping, view resolvers, local and theme resolvers.

DispatcherServlet is responsible for initializing the Spring Web MVC framework. It has to been configured in web.xml Continue reading

May 15 2015

Spring AOP Interview Questions

Spring AOP Interview Questions

What is a Concern?

Concern refers to part of the program divided based on the functionality. Concerns are of two types core and crosscutting. The concern that represents the core functionality is called as primary concerns. The concern which represents the secondary requirement is called crosscutting concerns. For example, Logging, transaction management, security etc.

What is Spring AOP?

Spring Aspect Oriented Programming (AOP) is a programming methodology that allows us to build core concerns and crosscutting concerns separately and provides dynamic way of introducing the crosscutting before, after or around the core concerns. The key unit of modularity in AOP is aspect.

What do you mean by join point? Continue reading

May 13 2015

Spring Inject Annotation

Spring Inject Annotation

Spring 3.0 provides support for JSR-330 standard annotations and these annotations are similar to spring annotations. If you want to use them you need to include javax.inject jar in your classpath.

Inject

Inject is a J2EE specific annotation used for injecting or autowiring one class into another class. It is similar to Autowired spring annotation. Like Autowired, Inject can also be used at the class-level, field-level, method-level and constructor-argument level.

Difference between Autowired and Inject is Autowired supports required attribute whereas Inject does not support required attribute

@Inject performs injection by type, if you have more than one bean of the specific type, the container will throw ambiguity error. To Solve this problem @Named annotation need to be used. Continue reading

Category: Spring | LEAVE A COMMENT
May 8 2015

org.hibernate.hibernateexception: /hibernate.cfg.xml not found

org.hibernate.hibernateexception /hibernate.cfg.xml not found

This exception will be thrown when hibernate is not able to locate hibernate.cfg.xml file in the root directory of your application’s classpath.

Example 

In the below example, if the hibernate.cfg.xml is not available in your src folder org.hibernate.hibernateexception will be thrown

HibernateUtility.java Continue reading

May 8 2015

Difference between get and load in hibernate

Difference between get and load in hibernate

Hibernate Session provides get and load methods to retrieve the persistent objects from database by identifier.

Object load(Class theClass,Serializable id)  throws HibernateException

Object get(Class clazz,Serializable id) throws HibernateException

Following are the differences between load and get method in hibernate

  1. If load method cannot find the object in the cache or database, an ObjectNotFoundException is thrown whereas get method returns null if it is not able to find the object.

Continue reading

April 30 2015

Hibernate object states – Transient,Persistent and Detached

Hibernate object states

The following are the hibernate object states

Transient object state

An object which is not associated with hibernate session and does not represent a row in the database is considered as transient. It will be garbage collected if no other object refers to it.

You have to use save, persist and saveOrUpdate methods to persist the transient object.

Persistent object state

An object which represents a row in the database or a transient object which is associated with session is considered as persistent object. It is the existing object which is retrieved from database or a transient object associated with session and which is about to be saved. Continue reading

April 30 2015

Difference between save and persist in hibernate

 Difference between save and persist in hibernate       

The save and persist methods are used to persist the transient instance. Save and persist method results a sql insert query. If any properties are updated after the save or persist method and before the transaction is committed or session is flushed, the changes will be saved to the database using update query.

public Serializable save(Object object) throws HibernateException

public void persist(Object object) throws HibernateException

Difference between save and persist methods Continue reading

April 28 2015

Named query in hibernate

Named query in hibernate

A named query is query which can be defined once and use multiple times. Named queries are useful if you want to reuse complex or same query at various places. Named queries stored in hibernate mapping files are easier to maintain than queries scattered all over the Java code. It has a name to be identified and the name have to be unique.

Hibernate named queries are easy to cache if necessary and provides a slight performance advantage. The getNamedQuery() method obtains a Query instance for a named query.

Example Continue reading

April 27 2015

Hibernate createsqlquery example

Hibernate createsqlquery example

Hibernate allows us to write the queries in native sql. You can execute sql queries from the session with the createSQLQuery() method on the Session interface. The createSQLQuery is used to create a SQL query using the database specific features.

public SQLQuery createSQLQuery(String sqlString) throws HibernateException

Scalar queries

SQL query is to get a list of scalars (values).By default SQL result set rows are returned as Object array.

Example Continue reading