java-logo

Exception in thread “main” java.lang.IllegalStateException: CGLIB is required to process @Configuration classes

During developing Spring applications we might get below exception, basically we might get this exception when we are using “@Configuration” annotation in our Application and we are not adding the “cglib-nodep”  jar in to class path.   Mar 11, 2015 3:59:36 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1d8c528: startup date [Wed Mar 11 15:59:36 IST 2015]; root […]

spring1

spring javaconfig example – @Configuration

In this tutorial we are going to explore how we can achieve to build a completely XML-free sample Spring  application. Before Spring 3.0  we are using XML based approach to configure our beans in xml file. But in Spring 3.0 we have new feature “@Configuration”  which is useful to configure our beans in programmatically. let us have […]

hibernate1

Generator classes in Hibernate

Generator classes are used to generate the ‘identifier or primary key value‘ for a persistent object while saving an object in database. Hibernate provides different primary key generator algorithms. All hibernate generator classes implements hibernate.id.IdentifierGenerator interface, and overrides the generate(SessionImplementor,Object) method to generate the ‘identifier or primary key value‘. If we want our own user […]

hibernate1

persist() and replicate() methods in Hibernate

persist(): 

It is equivalent to save(object) , but save(object) method returns identifier and persist(object) returns nothing. Use save() method, If you are using generator class to generate the identifier and you want to know the identifier value. Use persist() method, if you don’t want to know the generated identifier. replicate(): Use to move the […]

hibernate1

getTransaction(), beginTransaction() and getIdentifier() in Hibernate

Transaction object can be created by 2 ways

getTransaction(): Returns the Transaction object associated with current session. It returns the same Transaction object for every request.

We need to call begin() method on Transaction object to start the transaction.

beginTransaction(): Returns different transaction objects. For each and every request transaction object creates a~lcl begins new transaction context.

getIdentifier(): Use to […]

hibernate1

merge() method in Hibernate

merge(): It merge the detached object data into persistent data.

Lets understand merge() method by example. Employee table in database

 

Output in Eclipse

Employee table in database,After execution of above program  

Before 23rd line, emp1 is in Persistent state and emp2 is in detached state. In 23rd line, merge() method […]

hibernate1

refresh() method in Hibernate

refresh(): It is used to synchronize database data with session data.

Lets see the importance of refresh() method with the below scenarios. Scenario 1: One session and calling one time get() method Employee table

Application code:

Output

Explanation session.get(Employee.class, 1) hits the database and fetches the data from database and assign the data […]

hibernate1

flush() method in Hibernate

flush(): Forces the session to flush. It is used to synchronize session data with database.

When you call session.flush(), the statements are executed in database but it will not committed. If you dont call session.flush() and if you call session.commit() , internally commit() method executes the statement and commits. So commit()= flush+commit. So seesion.flush() just […]

hibernate1

contains() and isConnected methods in Hibernate

contains(Object object): Used to check whether the instance is associated with the session or not.

Example on contains(object)

Output:

isConnected(): Used to check whether session is currently connected or not.

Example on isConnected()

Output:

 

hibernate1

clear(), evict() and close() methods in Hibernate

clear():  Completely clear the session and is used to dissociate/disconnect all the objects from the session.

Example on clear() Database table before execution

 

Database table after execution

 After calling session.clear(), emp1 and emp2 objects are disconnected from the session object. i.e emp1 and emp2 objects are moved from persistent state to detached […]