Layering with Spring JPA

I am looking for a layered solution for my web application. I would like to implement my application using a separate schema model. I am thinking to have a data source per session. For this I put datasource and entitymanger in session scope, but that doesn't work. I'm going to load data-access-context.xml (which includes a data file and another beans repository file) when the user enters username and password and tenantId. I would like to know if this is a good solution?

+3


source to share


2 answers


The multi-user process is a bit of a tricky issue and needs to be handled on the JPA vendor side, so nothing or very little changes from the point of view of the client code. supports layering (see: EclipseLink / Development / Indigo / Multi-Tenancy ), added it recently.

Another approach is to use AbstractRoutingDataSource

, see: Multiple leases in Hibernate .



Using session scope is too risky (you will also get thousands of database connections, multiple for each session / user. Finally EntityManager

, the underlying database connections are not serializable, so you cannot migrate the session and scale the application correctly.

+2


source


I have worked with several multi-user systems. The challenge here is how you store

  • open architecture and
  • provide a solution that will evolve in your business.

Let's look at the second call first. Tiered systems tend to evolve where you need to support use cases where the same data (record) can be accessed by multiple tenants of different capacities (e.g. https://bugs.eclipse.org/bugs/show_bug.cgi?id = 355458 ). Thus, the system ultimately needs an access control list.



To keep the architecture open, you can use code (like JPA). Coding in EclipseLink or Hibernate makes me awkward.

Spring Security ACL provides a very flexible community to support both of these problems. Try it. I did and was pleased with this performance. However, I must warn you, it took me some digging to get my head in it.

0


source







All Articles