Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: JSF/JPA problem Date: Tue, 13 Sep 2011 16:12:47 -0700 Organization: A noiseless patient Spider Lines: 101 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 13 Sep 2011 23:12:50 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="27809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KUVy07ZIKxcQ9YZU6aSamk8Y0N1mLW4I=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Cancel-Lock: sha1:POhh9PBGcEK5xP6plVtDf1IrqhI= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7993 On 9/13/2011 1:40 PM, Arved Sandstrom wrote: >> If you want container-managed then inject with @PersistenceContext, and >> specify JTA in your persistence.xml (Note: with application-managed >> you'd typically have RESOURCE_LOCAL). Hmm, ok not working still. I think I remember now switching from PersistenceContext to PersistenceUnit because the former was making errors on me too. Here's the full persistence.xml file (it's short). org.eclipse.persistence.jpa.PersistenceProvider jdbc/techdarwinia false Here's the error I'm getting now: WARNING: #{postBean.createNewPost()}: javax.persistence.TransactionRequiredException javax.faces.FacesException: #{postBean.createNewPost()}: javax.persistence.TransactionRequiredException at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) ... Caused by: javax.persistence.TransactionRequiredException at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:163) at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:145) at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:263) at com.techdarwinia.website.services.PostService.createPost(PostService.java:27) at com.techdarwinia.website.beans.PostBean.createNewPost(PostBean.java:167) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) which now moves the error up to the em.persist( post ); line, one above the previous error at the line em.flush(); Here's what I changed the PostService to: import com.techdarwinia.website.dto.Post; import javax.ejb.Stateless; import javax.faces.bean.ManagedBean; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author Brenden */ @ManagedBean @Stateless public class PostService { @PersistenceContext EntityManager em; public void createPost( Post post ) { em.persist( post ); em.flush(); } } Anyone got ideas?