i need to select an EntityManager in my JavaEE6 project (JBoss7) depending of a login session.
A user "Peter" will result in using databse dbPeter and a user "Paul" will result in using database dbPaul.
The question is now, how can i produce an entity manager that is automatically bind to the according database/persistence unit?
I use CDI to inject the EntityManager. So my first step is to have a producer for EntityManager that looks for the login information from the session and selects the database.
So, how do i select the database/persistence context in this prducer??
Since Jboss7 i can't see any jndi entry for the persistence unit anymore, so a jndi lookup can not be considered.
I tried using
@Produces
public EntityManager produceEM() {
EntityManagerFactory managerFactory = Persistence.createEntityManagerFactory( "dbPaul" );
return managerFactory.createEntityManager();
}
but this fails during deployment with
> HHH000231: Schema export unsuccessful: java.sql.SQLException: You cannot set autocommit during a managed transaction!
Thats ok because the place where the em is injected is mostly inside a transaction.
Anyone an idea?
以上就是JavaEE6: HowTo select a persistence unit for entity manager by login information的详细内容,更多请关注web前端其它相关文章!