Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] TransactionRequiredException in JPA/JSF application

Zadir,
    Hi, If you are getting the same TransactionRequiredException then I would start with verifying that your <jta-data-source> is set to a transactional datasource or one that supports transactions.
    See the following example for GlassFish V2
http://wiki.eclipse.org/EclipseLink/Examples/JPA/GlassFishV2_Web_Tutorial#Persistence.xml

	thank you
	/michael


Michael O'Brien wrote: 1/11/2009 4:10 PM
Websta,
   Hi, keep in mind that the transaction-type defaults to either value depending on where it is deployed.  I usually explicitly set it so I am forced to modify code when moving and app between SE and EE. 

   transaction-type defaults:
   SE = RESOURCE_LOCAL
   EE = JTA

   From the behavior of your app, it looks like you may be running with the default transaction-type (so JTA on GlassFish), I would have to see your persistence.xml to be sure.

   Also, verify that (if) you are running as JTA on the glassfish container that you don"t have transaction.begin()/commit() wrapper code around your entityManager interactions - like you would in an SE environment.
    You may want to verify that you are also running against a transactional defined DataSource if using JTA in the specified jta-data-source element so that the container can handle your transaction properly.

    Let us know what happens.
    Thank you
    /michael

----------Original Message----------

Zarar Siddiqi wrote:
Did you get this resolved?

I'm getting a similar error.  I even have the transaction type defined as
JTA in the persistence.xml:

<persistence-unit name="db" transaction-type="JTA">

Any ideas?




websta8 wrote:
  
Hello everybody,


I hope someone can solve my problem with Eclipse3.4, Glassfish v2.1
(9.1.1) (build b60f-fcs), EclipseLink 1.0.2:

My application (Eclipse dynamic web app + jpa 1.0 + jsf 1.2 facets)
consists of a stateless session bean, one entity bean and one jsf file.
Glassfish displays correct the jsf file with the button which is linked to
the store function in the stateless session bean.
When processing the line "em.persist(eb);" glassfish throws the following
TransactionRequiredException:


Caused by: javax.persistence.TransactionRequiredException
	at
com.sun.enterprise.util.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:236)
	at
com.sun.enterprise.util.EntityManagerWrapper.doTransactionScopedTxCheck(EntityManagerWrapper.java:200)
	at
com.sun.enterprise.util.EntityManagerWrapper.persist(EntityManagerWrapper.java:426)
	at testglassfish1.beans.ControllerBean.store(ControllerBean.java:20)
	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:597)
	at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
	at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
	at
com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
	at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
	... 45 more


Writing a JavaSE application using JPA & EclipseLink (Resource_local with
Derby) works like a charm. 
I tried different configurations with Resource_local,
EntityManagerFactory, with explicit starting transaction
(em.getTransaction.begin() & commit()) etc. but it doesn't work.

Any hints would be welcome!!


thx in advance,
websta





SOURCE of SESSION BEAN

@Stateless
public class ControllerBean implements ControllerBeanInterface
{
	@PersistenceContext
	private EntityManager em;
	
	public ControllerBean() {}
	
	public String store()
	{
		EntityBean eb = new EntityBean();
		eb.setName("name");
		
		em.persist(eb);		

		return "SUCCESS";
	}
}


SOURCE of ENTITY BEAN

@Entity
public class EntityBean implements Serializable
{
	@Id
	@GeneratedValue
	@Column(name="id")
	private BigInteger id;
	
	@Column(name="name", length = 200)
	private String name;
	
// + setters and getters for the fields
}


SOURCE of PERSISTENCE.XML

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
	<persistence-unit name="testglassfish1_db" transaction-type="JTA">
		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		<jta-data-source>jdbc/__default</jta-data-source>
		<class>testglassfish1.beans.EntityBean</class>
		<exclude-unlisted-classes>true</exclude-unlisted-classes>
		<properties>
			<property name="eclipselink.target-server" value="SunAS9" />
			<property name="eclipselink.logging.level" value="FINEST" />
		</properties>
	</persistence-unit>
</persistence>


SOURCE of FACES-CONFIG.XML

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
	<managed-bean>
		<managed-bean-name>controller</managed-bean-name>
	
<managed-bean-class>testglassfish1.beans.ControllerBean</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
</faces-config>


SNIP of PAGE1.JSP

<f:view>
<h1>Page1</h1>
	<h:form>
		<h:commandButton action=""
value="save"></h:commandButton>
		<h:messages layout="table"></h:messages>
	</h:form>
</f:view>



GLASSFISH STARTUP

INFO: SharedSecrets.getJavaNetAccess()=java.net.URLClassLoader$7@1c407d5
INFO: deployed with moduleid = testglassfish1
INFO: naming.bind
AM FEINSTEN: property=eclipselink.logging.level; value=FINEST; translated
value=FINEST
AM FEINSTEN: property=eclipselink.logging.level; value=FINEST; translated
value=FINEST
AM FEINSTEN: Begin predeploying Persistence Unit testglassfish1_db; state
Undeployed; factoryCount 0
AM FEINSTEN: property=eclipselink.orm.throw.exceptions; default value=true
AM FEINSTEN: property=eclipselink.weaving.changetracking; default
value=true
AM FEINSTEN: property=eclipselink.weaving.lazy; default value=true
AM FEINSTEN: property=eclipselink.weaving.eager; default value=false
AM FEINSTEN: property=eclipselink.weaving.fetchgroups; default value=true
AM FEINSTEN: property=eclipselink.weaving.internal; default value=true
FEINER: Searching for default mapping file in
file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/classes/
FEINER: Found a default mapping file at
file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/classes/META-INF/orm.xml
for root URL
file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/classes/
FEINER: Searching for default mapping file in
file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/classes/
KONFIG: The access type for the persistent class [class
testglassfish1.beans.EntityBean] is set to PROPERTY.
KONFIG: The alias name for the entity class [class
testglassfish1.beans.EntityBean] is being defaulted to: EntityBean.
KONFIG: The table name for entity [class testglassfish1.beans.EntityBean]
is being defaulted to: ENTITYBEAN.
FEINER: Class [testglassfish1.beans.EntityBean] registered to be processed
by weaver.
AM FEINSTEN: End predeploying Persistence Unit testglassfish1_db; state
Predeployed; factoryCount 1
INFO: Initializing Sun's JavaServer Faces implementation (1.2_04-b22-p05)
for context '/testglassfish1'
INFO: Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
INFO: Creating LRUMap cache instance using parameters:
{com.sun.faces.injectionProvider=com.sun.faces.vendor.GlassFishInjectionProvider,
com.sun.faces.validateXml=true, com.sun.faces.forceLoadConfiguration=true,
org.ajax4jsf.VIEW_HANDLERS=com.sun.facelets.FaceletViewHandler,
org.richfaces.SKIN=classic}
INFO: Creating LRUMap cache instance of default capacity
INFO: Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
INFO: Creating LRUMap cache instance using parameters:
{com.sun.faces.injectionProvider=com.sun.faces.vendor.GlassFishInjectionProvider,
com.sun.faces.validateXml=true, com.sun.faces.forceLoadConfiguration=true,
org.ajax4jsf.VIEW_HANDLERS=com.sun.facelets.FaceletViewHandler,
org.richfaces.SKIN=classic}
INFO: Creating LRUMap cache instance of default capacity



OUTPUT when button is clicked:

INFO: Creating LRUMap cache instance of default capacity
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-core.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-html.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/jsf-facelets.jar!/META-INF/jsf-ui.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-core.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/jsf-facelets.jar!/META-INF/jstl-fn.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/richfaces-ui-3.2.2.SR1.jar!/META-INF/a4j.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/richfaces-ui-3.2.2.SR1.jar!/META-INF/ajax4jsf.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/richfaces-ui-3.2.2.SR1.jar!/META-INF/jsp.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/richfaces-ui-3.2.2.SR1.jar!/META-INF/rich.taglib.xml
INFO: Added Library from:
jar:file:/D:/java/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/testglassfish1/WEB-INF/lib/richfaces-ui-3.2.2.SR1.jar!/META-INF/richfaces.taglib.xml
WARNUNG: PWC4011: Unable to set request character encoding to UTF-8 from
context /testglassfish1, because request parameters have already been
read, or ServletRequest.getReader() has already been called
AM FEINSTEN: Begin weaver class transformer processing class
[testglassfish1/beans/EntityBean].
AM FEINSTEN: Weaved persistence (PersistenceEntity)
[testglassfish1/beans/EntityBean].
AM FEINSTEN: Weaved change tracking (ChangeTracker)
[testglassfish1/beans/EntityBean].
AM FEINSTEN: Weaved fetch groups (FetchGroupTracker)
[testglassfish1/beans/EntityBean].
AM FEINSTEN: End weaver class transformer processing class
[testglassfish1/beans/EntityBean].
SCHWERWIEGEND: javax.persistence.TransactionRequiredException
...stack trace

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen:
http://www.gmx.net/de/go/multimessenger
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


    
  


Back to the top