What is final, finally and finalize in Java?

In this Article we will get know the significance of final, finally and finalize in Java. final: Final is a keyword in Java,which can be applied to variables, methods, class and local variables in Java What is final variable in Java? The variable which is declared with ‘final’ is know as final variable, It can be […]


What is Fail Fast vs Fail Safe Iterator in Java

In this tutorial we will learn what is Fail Fast what is  Fail Safe Iterator in java . This is the one of the main question in interview regarding Concurrency management.Before looking into “Fail Fast vs Fail Safe” we should aware of the term “Concurrent Modification” What is Concurrent Modification ? Is nothing but one […]


How To Convert String To Char Array In Java

In this tutorial we can see how to convert String to Char Array in Java, see the below example code.  




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 interface, and overrides the generate(SessionImplementor,Object) method to generate the ‘identifier or primary key value‘. If we want our own user […]


persist() and replicate() methods in Hibernate


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 […]


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 […]


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 […]


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:


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


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 […]


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)


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

Example on isConnected()