0

I am working on a web service based on Java EE, EJB, JSF and JPA. The service is provided to business customers, and the data stored for each customer is completely independent. What are the options for segmenting the data into different tables or databases, for each customer? E.g. there is an Account entity, and I want tables Account_customerA and Account_customerB, or different PostgreSQL databases*. The customer-ID will be determined from the subdomain or from a global user table.

Ideally we want to use the same EAR for all customers, for performance and maintenance reasons. As we are in the initial stages of the project, we are also interested in hearing options involving other frameworks like Spring.

*The rationale behind this request is one of security -- specifically to prevent mistakes that expose data between customers (so the best is to have different databases and/or database users). I also expect the lookup performance to be better with distinct tables / databases, though there will of course be a memory overhead.

1 Answers1

0

Most likely, you'll need to inject references to the EntityManagerFactory object, in order to get your the appropriate EntityManager for the database appropriate for the provided Account.

This question looks like it might be a similar issue that you're looking at

Handle multiple EntityManager in Java EE application

Community
  • 1
  • 1
EdH
  • 4,918
  • 4
  • 24
  • 34
  • I'll look into the EntityManagerFactory, it's probably what I need. If it's too cumbersome, I suppose I can consider deploying an instance of the application for each customer. Thanks for the reply, i'll accept it – Marius Bjørnstad Mar 09 '14 at 23:44