On 27-07-2012 18:50, Romain Manni-Bucau wrote: > Produces the emf too, no? > Le 27 juil. 2012 18:20, "Martin Kjær Jørgensen" <[email protected]> a écrit : > >> On 27-07-2012 08:26, Romain Manni-Bucau wrote: >>> Yes normal. Doing it use @inject and not @persistencecontext >>> >>> -Romain >>> Le 27 juil. 2012 07:30, "Martin Kjær Jørgensen" <[email protected]> a écrit : >>> >>>> On 26-07-2012 15:33, Romain Manni-Bucau wrote: >>>>> Hi, >>>>> >>>>> implementing JPA you can do what you want. >>>>> >>>>> You get properties of your persistence unit and you can even ignore >>>>> datasources if you are not contacting a RDBMS. >>>>> >>>>> Then do your own logic with these properties. >>>>> >>>>> Then you can use @persistenceContext as usually. >>>>> >>>>> - Romain >>>>> >>>>> >>>>> 2012/7/26 Martin Kjær Jørgensen <[email protected]> >>>>> >>>>>> I'm using the TomEE 1.0.0+ stack developing a JEE6 Web App, and I'm >>>>>> looking for a way to make userspecific JTA EntityManager's using CDI >> or >>>>>> Resource injections. >>>>>> >>>>>> The reason for this is the users in the system are created in a LDAP >>>>>> directory and used by Tomcat (TomEE) and the database server for >>>>>> authentication. So after a user has logged in on a JSF form the same >>>>>> username and password should be used to make EntityManager's. >>>>>> >>>>>> It seems that the JPA is designed to use only one username and >> password >>>>>> for all users of the application. >>>>>> >>>>>> Have anyone succesfully created a completely user-specific web >>>>>> application all the away down to the databaselevel and anywhere else? >>>>>> >>>>> >>>> >>>> It doesnt seem so. For instance, if I create a EntityManager with a CDI >>>> @Producer method like so (EntityManagerFactory being a private field): >>>> >>>> @Produces >>>> public OpenJPAEntityManager produceEntityManger() { >>>> Map p = new HashMap(); >>>> p.put("javax.persistence.jdbc.user", "abc"); >>>> p.put("javax.persistence.jdbc.password", "abc"); >>>> EntityManager em = emf.createEntityManager(p); >>>> return em; >>>> } >>>> >>>> ... I get a warnings in my log saying: >>>> >>>> WARNING - An unrecognized EntityManager property was passed to >>>> createEntityManager and will be ignored. Key: >>>> "javax.persistence.jdbc.password", Value: "class java.lang.String:abc". >>>> WARNING - An unrecognized EntityManager property was passed to >>>> createEntityManager and will be ignored. Key: >>>> "javax.persistence.jdbc.user", Value: "class java.lang.String:abc". >>>> >>>> >>>> If i provide it with OpenJPA specific properties like so: >>>> >>>> p.put("openjpa.ConnectionUserName", "abc"); >>>> p.put("openjpa.ConnectionPassword", "abc"); >>>> p.put("openjpa.Connection2UserName", "abc"); >>>> p.put("openjpa.Connection2Password", "abc"); >>>> >>>> ... I still get warnings, but not for ConnectionUserName and >>>> ConnectionPassword: >>>> >>>> WARNING - An unrecognized EntityManager property was passed to >>>> createEntityManager and will be ignored. Key: >>>> "openjpa.Connection2Password", Value: "class java.lang.String:abc". >>>> WARNING - An unrecognized EntityManager property was passed to >>>> createEntityManager and will be ignored. Key: >>>> "openjpa.Connection2UserName", Value: "class java.lang.String:abc". >>>> >>>> Apparently, the EntityManager still uses the username and password from >>>> the resource because my persistence code runs without exceptions. It >>>> should fail because I provided wrong username and password (abc:abc). >>>> >>> >> >> I'm already @Inject'ing EntityManager from my producer class. I'm only >> using @PersistenceContext for the EntityManagerFactory. >> >
No i dont have a producer for EMF.
