Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7993
| From | markspace <-@.> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JSF/JPA problem |
| Date | 2011-09-13 16:12 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <j4oo1i$r51$1@dont-email.me> (permalink) |
| References | <j4nvr9$4ld$1@dont-email.me> <VZObq.20744$oz6.19581@newsfe11.iad> <XcPbq.17471$CQ4.165@newsfe09.iad> |
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).
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="techDarwinia2PU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/techdarwinia</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
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?
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
JSF/JPA problem markspace <-@.> - 2011-09-13 09:19 -0700
Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 17:24 -0300
Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 17:40 -0300
Re: JSF/JPA problem markspace <-@.> - 2011-09-13 15:38 -0700
Re: JSF/JPA problem markspace <-@.> - 2011-09-13 17:06 -0700
Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 22:28 -0300
Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-13 22:31 -0300
Re: JSF/JPA problem markspace <-@.> - 2011-09-13 19:27 -0700
Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-14 05:59 -0300
Re: JSF/JPA problem markspace <-@.> - 2011-09-14 10:36 -0700
Re: JSF/JPA problem Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-14 17:51 -0300
Re: JSF/JPA problem markspace <-@.> - 2011-09-13 16:12 -0700
csiph-web