[jboss-user] [JBoss Seam] - Entity Manager Woes
msduk
do-not-reply at jboss.com
Thu Dec 14 09:20:25 EST 2006
Ok I have oficially downgraded myslef to n00b after a large amount of previous success with seam.
Basically I am trying to use the entity manager from an external thread. I have the entity manager.
| EntityManager em = null;
|
| try {
| jndi = new InitialContext();
| //TODO get name from settings
| EntityManagerFactory emf = (EntityManagerFactory)
| jndi.lookup("java:/myEntityManagerFactory");
| em = emf.createEntityManager();
| NrgOrder nrgOrder = em.find(NrgOrder.class, 1);
| nrgOrder.setState(NrgOrder.SEND_ERR);
| em.persist(nrgOrder);
| log.debug(nrgOrder.getState());
| em.close();
| } catch (Exception e) {
| e.printStackTrace();
| } finally {
| try {
| if(jndi!=null) jndi.close();
| } catch (NamingException e) {
| e.printStackTrace();
| }
| }
the myEntityManagerFactory is the same one as seam references (I think) as defined by the following...
<persistence>
| <persistence-unit name="nrg2">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/myDatasource</jta-data-source>
| <properties>
| <!-- <property name="hibernate.hbm2ddl.auto" value="create"/> -->
| <property name="hibernate.cache.use_query_cache" value="true"/>
| <property name="hibernate.show_sql" value="true"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/myEntityManagerFactory"/>
| <property name="jboss.entity.manager.jndi.name" value="java:/entityManager"/>
| </properties>
| </persistence-unit>
| </persistence>
|
|
| and...
|
| <?xml version="1.0" encoding="utf-8"?>
| <components>
| <component name="org.jboss.seam.core.init">
| <property name="debug">true</property>
| <property name="myFacesLifecycleBug">true</property>
| <property name="jndiPattern">my/#{ejbName}/local</property>
| </component>
|
| <component name="entityManager" class="org.jboss.seam.core.ManagedPersistenceContext">
| <property name="persistenceUnitJndiName">java:/myEntityManagerFactory</property>
| </component>
|
| <component name="org.jboss.seam.core.manager">
| <property name="conversationTimeout">300000</property>
| </component>
|
| <component class="org.jboss.seam.core.Ejb" installed="false"/>
| </components>
|
|
I am able to load using the above snippet but no updates are taking place.
I am calling close() with no joy. I tried calling flush() but i get
14:17:30,375 ERROR [STDERR] javax.persistence.TransactionRequiredException: no transaction is in progress
| 14:17:30,375 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:293)
| 14:17:30,375 ERROR [STDERR] at halvor.schedulers.PendingOrderQuartzTarget.execute(PendingOrderQuartzTarget.java:95)
| 14:17:30,375 ERROR [STDERR] at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
| 14:17:30,375 ERROR [STDERR] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
If i try and use transaction EntityTransaction et = em.getTransaction();
et.begin(); I get...
14:19:00,156 ERROR [STDERR] java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
| 14:19:00,156 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316)
| 14:19:00,156 ERROR [STDERR] at halvor.schedulers.PendingOrderQuartzTarget.execute(PendingOrderQuartzTarget.java:91)
| 14:19:00,156 ERROR [STDERR] at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
| 14:19:00,156 ERROR [STDERR] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
I am clearly missing something obvious so can someone point it out to me plesae.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993857#3993857
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993857
More information about the jboss-user
mailing list