Entity is not saved in Hibernate Multi-tenant web application

Viewed 290

My application is as follows:

  • Spring 4, Spring MVC, Spring Data JPA, Hibernate 5.0.12
  • DB2 as database
  • Websphere 16 as server

Also is my web application multi-tenant based on schema. The implementation is almost like this: http://stuartingram.com/2016/10/02/spring-boot-schema-based-multi-tenancy/

Everything is working fine with multi-tenant when a user does CRUD operations on entities but when I try to seed some data on startup (ContextRefreshedEvent) the data is not inserted to the schemas. But a previous request if data is in there, gives the right results that no data is there. I need to add here that one schema has already the seeded data.

The procedure is as follows:

  1. Set tenant and with this the schema of the database
  2. check if repository count is 0
  3. if this is the case, create a new entity
  4. save the new entity

The result of point 1 is correct, and there is no exception when the entity is saved (3). But there is no data in the database after the seeding. Also is the tenant and schema correctly set before the repository methods are called.

A normal saving after the startup in a schema is successful.

What could be the reason why saving data to different schemes is not working before the application started completely?

Edit:

I tested the Code also on a Tomcat 8.5.4 and it is working. So there is something different in the implementation concerning WebSphere in Spring/Hibernate I guess.

0 Answers
Related