[jboss-user] [JBoss Seam] - Pb Initializing database on app startup with postInitializat
zdaler
do-not-reply at jboss.com
Thu Sep 6 10:37:54 EDT 2007
I launch a method on application startup using the org.jboss.seam.postInitialization event. It work fine except if I access the database (and I need to) :
using seam managed entity manager :
@In
| private EntityManager em;
|
| @Observer("org.jboss.seam.postInitialization")
| private void setupAFewThings() throws ComentSystemException {
| MyObject w = new MyObject() ;
| w.setName("test_name") ;
| em.getTransaction().begin();
| em.persist(w) ;
| em.getTransaction().commit();
| }
or manually creating a new entity manager like this :
@Observer("org.jboss.seam.postInitialization")
| private void setupAFewThings() throws ComentSystemException {
| MyObject w = new MyObject() ;
| w.setName("test_name") ;
| EntityManagerFactory emf = Persistence.createEntityManagerFactory("myDatabase");
| EntityManager em = emf.createEntityManager();
| em.getTransaction().begin();
| em.persist(w) ;
| em.getTransaction().commit();
| }
I get the same error ("java.lang.IllegalStateException: JTA EntityManager cannot access a transactions") :
anonymous wrote : 16:26:18,530 ERROR [[/coment_demo]] Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.jboss.seam.servlet.SeamListener
| java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
| at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316)
| at com.sopinspace.coment.core.WorkflowManager.addDefaultWorkflow(WorkflowManager.java:53)
| at com.sopinspace.coment.core.WorkflowManager.create(WorkflowManager.java:62)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
| at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
Any help ?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4081692#4081692
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4081692
More information about the jboss-user
mailing list