-
1. Re: ManagedPersistenceContext anyone?
gavin.king Nov 3, 2005 8:23 AM (in response to geraldloeffler)Follow the instructions here:
http://docs.jboss.com/seam/reference/en/html/configuration.html#d0e1597
ie.
org.jboss.seam.init.managedPersistenceContexts bookingDatabase
bookingDatabase.persistenceUnitName java:/EntityManagerFactories/bookingData
and use
org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener -
2. Re: ManagedPersistenceContext anyone?
geraldloeffler Nov 4, 2005 4:13 AM (in response to geraldloeffler)thanks Gavin, but i had (of course ;-) followed the docs and when that didn't work i posted here
To elaborate:
If you look into org.jboss.seam.core.ManagedPersistenceContext.getEntityManagerFactory() you'll see that the persistenceUnitName must actually be without the "java:/EntityManagerFactories/"-prefix, so my seam.properties isorg.jboss.seam.core.init.managedPersistenceContexts supplierdirDatabase
persistence.xml matches this<entity-manager> <name>supplierdirDatabase</name> </entity-manager>
And the session bean has the correct injection set-up:@In(create = true, required = true) EntityManager supplierdirDatabase;
But this doesn't work:
1. the EntityManager injected into my session bean is null (or it is not injected).
2. there actually is a ManagedPersistenceContext instance:INFO [org.jboss.seam.Component] Component: supplierdirDatabase, scope: CONVERSATION, type: JAVA_BEAN, class: org.jboss.seam.core.ManagedPersistenceContext
3. but there is no evidence (log-output, exception) that ManagedPersistenceContext.create() is ever executed, so there is probably no JNDI lookup for the EntityManagerFactory performed.
4. ManagedPersistenceContext doesn't have a @Name (seems strange)
thanks again,
gerald -
3. Solution: ManagedPersistenceContext anyone?
geraldloeffler Nov 7, 2005 8:05 AM (in response to geraldloeffler)In case anybody is interested in the solution to this:
the scenario and code outlined above works just fine, it's just that the EntityManager is injected into the statefull session bean later than expected. In particular (and really not surprisingly), when the @PostConstruct callback of the session bean is executed, Seam will not have injected the EntityManager yet. The solution is thus to explicitly retrieve it from the Seam context in that callback (and rely on Seam injection in all business methods):@Stateful @Name("SupplierSearch") //... public class SupplierSearchController implements SupplierSearch, Serializable { @In(create = true, required = true) private EntityManager supplierdirDatabase; @PostConstruct public void init() { supplierdirDatabase = (EntityManager) Component.getInstance("supplierdirDatabase", true); // use supplierdirDatabase } public String search() { // use supplierdirDatabase, relying on its injection } }
The Seam docs should still be corrected to reflect the correct name to be given to a managedPersistenceContext in seam.properties, though (see above).
cheers,
gerald -
4. Re: ManagedPersistenceContext anyone?
rdewell Nov 7, 2005 12:09 PM (in response to geraldloeffler)Gerald, I think you need to use the Seam annotation @Create instead of @PostConstruct if you want to access Seam injected objects at that particular lifecycle. That may be off-topic to your original post, but it does keep you from having to do a lookup.
-
5. Re: ManagedPersistenceContext anyone?
gavin.king Nov 8, 2005 5:33 PM (in response to geraldloeffler)"rdewell" wrote:
Gerald, I think you need to use the Seam annotation @Create instead of @PostConstruct if you want to access Seam injected objects at that particular lifecycle. That may be off-topic to your original post, but it does keep you from having to do a lookup.
Right. -
6. Re: ManagedPersistenceContext anyone?
geraldloeffler Nov 9, 2005 5:56 AM (in response to geraldloeffler)thank you both - @Create instead of @PostConstruct did indeed do the trick.
cheers,
gerald