How to resolve [A collection with cascade=“all-delete-orphan” was no longer referenced by the owning entity instance]

If you have come across the above error, chances are :

  1. You have two entities, a Parent and its Child.
  2. You are deleting (Or removing some old and adding new) Child records and updating the Parent.

Going through this post will help you resolve this error and provide you insight on the details of the solution (more…)

Continue Reading

How to load properties file in Spring / Various ways to load Properties file in Spring / Supply bean values from Properties file

Scenario

It is always advisable not to use configuration values inside your application code directly. Rather, supply them through configuration files which are external to the code. For Example, almost all applications involve database interaction wherein they connect to a database. Obviously there are database connection parameters such as database server url, database port etc. If they are hard-coded inside the code, then for every change in those parameters (suppose for a change in database server URL), the code will have to be touched. If they are supplied through an external properties file, then changing them would only require a restart of application or not even that in some cases. (more…)

Continue Reading

How to create bean in Spring / Various ways to create a bean in Spring / Create a bean in Spring without new keyword

Bean…What is it ?

A bean in java context is a simple java class which has some properties (also called fields) and their getter and setter methods. These properties can be regarded as instance variables of the bean. The name of the properties and their getter/setter methods should adhere to the JavaBeans specifications (should start with a small letter, should be camel-case and so on). (more…)

Continue Reading

How to version rows automatically in Hibernate / Optimistic locking in Hibernate / Version-controlled optimistic concurrency control in Hibernate

Practical Scenario

Two users are working on a project and they both are currently viewing a bug or an enhancement in a project management application. Let’s say one user knows that it is a duplicate bug while the other does not know and thinks that this needs to be done. Now one user changes its status as IN PROGRESS and the other user marks it as DUPLICATE at the same time but the request with status as DUPLICATE goes a bit early to the server and the request with status IN PROGRESS arrives later. What will be the current status?

(more…)

Continue Reading

How to solve org.hibernate.HibernateException: No CurrentSessionContext configured!

When using Hibernate in your application, there are bright chances that you have encountered the error org.hibernate.HibernateException: No CurrentSessionContext configured!. Stack trace of the error would have been :

Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:690)
at com.codippa.Main.main(Main.java:16)

(more…)

Continue Reading
Close Menu