[jboss-user] [JBoss Seam] - Can't get Seam managed persistance working in an app scoped

krica do-not-reply at jboss.com
Wed Dec 13 02:51:40 EST 2006


OK, this is not really a big deal, because it works when I change it to EJB managed (i.e. @PersistenceContext), but I'ld like to understand why it doesn't work.

I have an application-scoped bean that should be initialized at startup:


  | @Stateful
  | @Name("anonUserFactory")
  | @Startup(depends="org.jboss.seam.core.ejb")
  | @Scope(ScopeType.APPLICATION)
  | public class AnonUserFactory implements AnonUserFactoryInterface {
  | 
  |     @Logger
  |     protected Log log;
  | 
  |     private User anonUser;
  | 
  |     @In(create = true)
  |     EntityManager theDatabase;
  | 
  |     @Create
  |     public void createAnonUser() {
  |         try {
  |             anonUser = (User) theDatabase.createQuery("blah blah").getSingleResult();
  |             anonUser.populatePermissions();
  |         }
  |         catch (NoResultException e) {
  |             log.fatal("Could not load anonymous user", e);
  |             throw e;
  |         }
  |     }
  | 
  |     @TransactionAttribute(NOT_SUPPORTED)
  |     public User getAnonUser() {
  |         return anonUser;
  |     }
  | 
  |     @Remove
  |     @Destroy
  |     public void destroy() {
  |     }
  | }
  | 

For some reason, theDatabase is null when I try to use it. This same injected EntityManager works in other (non-startup) classes, so the datasource and all that is set up correctly. I get no exception, except of course the NPE when trying to use the EntityManager.

If I may throw in a related question. Seeing as this EntityManager is not needed after the @Create method, how can I close it. If I do, I get the exception stating that I cannot call close() on injected components. I've tried to get it via "Component.getInstance("em", true)" and all sorts of things, but it always returns null.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993268#3993268

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993268



More information about the jboss-user mailing list