JavaEE6: HowTo select a persistence unit for entity manager by login information

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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准