Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » COMMIT is not allowed in a subordinate session
COMMIT is not allowed in a subordinate session [message #529214] Fri, 23 April 2010 13:23 Go to next message
njrfrens  is currently offline njrfrens Friend
Messages: 2
Registered: April 2010
Junior Member
In My Servlet, I am using JTA transaction which is not a CMT.
I am running this on Oracle XADatasource.

When I'm trying to perform the DB operation, I'm getting the
Exception saying "COMMIT is not allowed in a subordinate session "

My Servlet code is :
public class BatchServlet extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	PrintWriter out = null;

	EntityManagerFactory emf;

	EntityManager em;

	UserTransaction utx;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		out = response.getWriter();
		try {

		} catch (Exception ex) {
		} finally {
	public void initEM() throws Exception {
		em = emf.createEntityManager();

	public void closeEM() {
		if (em != null) {
	private void updateDB() throws Exception {
		Address address = em.find(Address.class, 50030L);
		out.println("County :: " + address.getCounty());
		address.setBuildingNumber("Building # ABC");
		out.println("Before Flush");
		out.println("After Flush");

	public BatchServlet() {

My Persistence.xml is
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	<persistence-unit name="PERUNIT" transaction-type="JTA">
		    <provider> org.eclipse.persistence.jpa.PersistenceProvider</provider> 
		    <class> com.test.Address</class>
	            <property name="eclipselink.logging.level" value="CONFIG"/>
	            <property name="javax.persistence.jtaDataSource" value="jdbc/MYXADS"/>
	            <property name="eclipselink.logging.level" value="FINE"/>

Any inputs please
Re: COMMIT is not allowed in a subordinate session [message #529621 is a reply to message #529214] Mon, 26 April 2010 14:50 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The issue is probably related to you acquiring your EntityManager outside of the JTA transaction. Unless you use a managed (injected) EntityManager, it will be bound to only the JTA transaction that it was acquired in. You can use joinTransaction() to join a new JTA transaction.

So either move your initEM after the begin, or call joinTransaction, or inject the EM.

See, oin_Transaction

James : Wiki : Book : Blog : Twitter
Previous Topic:Reading entity beans from Glassfish too slow
Next Topic:Persistence.xml problem
Goto Forum:

Current Time: Sat Nov 17 10:43:25 GMT 2018

Powered by FUDForum. Page generated in 0.02232 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top