detached entity passed to persist

I am in mid of a crud operation. This exception hit me today, when I updated an entity with @ManyToOne(cascade = CascadeType.ALL) relationship.

org.hibernate.PersistentObjectException: detached entity passed to persist: org.grassfield.feed.entity.Feed

To solve this bidirectional consistency problem, I need to change CascadeType.ALL to CasecaseType.MERGE.

Recently I shot this pretty lady (or mighty gentleman?) at Coney Island. This has no relation with this post anyway.

Recently I shot this pretty lady (or mighty gentleman?) at Coney Island. This has no relation with this post anyway.




ClassCastException: RestTemplate returning List instead of List


I have a POJO entity, say org.grassfield.Employee. I expose this as a REST services.

I consume this REST service,

List employeeList = restTemplate.getForObject(
"http://localhost:8080/api/v1/employees" ,

Instead of getting Employee object, I’m getting LinkedHashMap. So my code fails with ClassCastException: RestTemplate returning List<LinkedHashMap> instead of List<Employee>


Jackson uses LinkedHashMap to Serialize/De serialize the entity objects. When I consume the service using parameterized type reference, it works fine.

ResponseEntity<List> response =
"http://localhost:8080/api/v1/employees" ,
new ParameterizedTypeReference<List>(){});
List EmployeeList = response.getBody();


Spring file upload goes to Access denied page

Spring file upload goes to Access denied page

When Spring security is enabled, when I upload a file using multipart, SpringSecurity redirects me to Access denied url.

Refer to
I amend my Initializer as follows!

public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer{
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
insertFilters(servletContext, new MultipartFilter());

This error disappears. I landed in another problem. I’m resolving it now!!

Spring 5 migration: Unable to find setter method for attribute: [commandName]

Spring 5 Migration brings this pain. You will get this error during form submission.

Unable to find setter method for attribute: [commandName]

Command object does not work anymore.

Refer to

commandName is dead in Spring 5. Replace it with modelAttribute

<form:form modelAttribute="customer" action="customerView" method="post">

It worked! I need to make this change in my workspace now!

Migrating to Hibernate 5: Table ‘crm.hibernate_sequence’ doesn’t exist

I’m doing upgrading Spring 4 to Spring 5 and Hibernate 4 to 5.
My existing functionality refused to work. It broke with the following exception.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘crm.hibernate_sequence’ doesn’t exist

I’m using MariaDB/MySQL. I don’t have to maintain any sequence tables as Oracle. In addition, it was working without any issues. All my primary keys are autogenerated with the following annotations.

private Long id;

Thanks to

Adding to Hibernate properties solved the problem.

Eclipse tomcat does not start – May be locked by another process.

Happy Western New Year 2019!

I had a single spring web project. It became too big over the day. I had to split it up into multiple reusable projects so that I can build APIs. After I split it, Tomcat refused to start with the following error.

Publishing failed with multiple errors
Could not delete D:/Pandian/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/crm-upload/WEB-INF/lib. May be locked by another process.
Could not delete D:/Pandian/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/crm-upload/WEB-INF. May be locked by another process.

I tried to clean work folder, It doesn’t work. I did the following sequence to resolve this.

  1. Remove the tomcat server from eclipse server tab
  2. Restart Eclipse
  3. Add a new tomcat server
  4. Start the project


Read properties values in Java Spring Controller

To configure the environmental parameters, we read the values from property files. I have a controller which upload the files. The uploaded files will be saved in a location, which is defined in a property file. In this example I shall show you how to read the location name from the property file.

public class FileUploadController {
  String uploadFolder;

I have defined the property in file which is saved in src folder (or any other path defined in classpath.


Thats it! The variable uploadFolder will be assigned using the values given by