Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic Entity Manager in EJB
    text
    copied!<p>I have an application using Spring MVC and Spring Security.</p> <p>The application project has ejbs and web application.</p> <p>I have a common database for users and one database by users' group.</p> <p>So, when a user authenticate, Spring Security use the common database to check login/password and when a controller calls an ejb, the entity manager connects to the user's group database.</p> <p>My goal is : create users/groups and their associated database on the fly.</p> <h1>Example :</h1> <p>The common database <strong>localhost:3306 database_schema1</strong> contains</p> <pre><code> USERS ---------------------- | NAME | GROUP_ID | ---------------------- | Pierre | 1 | | Paul | 1 | | Jacques | 2 | ---------------------- GROUPS ------------------------------------------ | ID | URL | SCHEMA_NAME | ------------------------------------------ | 1 | localhost:3307 | database_schema1 | | 2 | localhost:3308 | database_schema1 | ------------------------------------------ </code></pre> <p>When Pierre authenticate, the home page call an ejb. This ejb has an entity manager which has to connects to group 1 database <strong>localhost:3307</strong> with schema <strong>database_schema1</strong></p> <p>If Jacques authenticate, it must be group 2 database.</p> <p>How can I do to tell to the entity manager to use a given database that I don't know when I build the project?</p> <p>I mean, I don't want to use persistence.xml in my ejb but dynamically initialize entity manager depending on the user authenticated. </p> <p>Does Persistence.createEntityManagerFactory() will work in this context ? And if it does, is it the best solution?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload