I don't know what is inside "getEntityManager()" but the error suggests to me that it might be returning a different entity manager instance at each call, and hence you are committing outside a transaction which is what this error is telling you.
I would code it like this: EntityManager em = getEntityManager(); em.getTransaction().begin(); em.persist(legalEntity); em.getTransaction().commit(); Chris -----Original Message----- From: gilbertoca [mailto:[email protected]] Sent: Friday, 14 May 2010 11:10 PM To: [email protected] Subject: Re: InvalidStateException Hi, I'm facing the same exception: > [INFO] Started Jetty Server > [INFO] Console reloading is ENABLED. Hit ENTER on the console to restart > the context. > [Click] [debug] GET http://localhost:8080/legalEntity.htm > 341 parkPU INFO [qtp33344123-18] openjpa.Runtime - Starting OpenJPA > 2.0.0 > 2711 parkPU TRACE [qtp33344123-18] openjpa.jdbc.SQL - <t 17368622, conn > 24437939> executing prepstmnt 7908994 SELECT SEQUENCE_SCHEMA, > SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES > 2711 parkPU TRACE [qtp33344123-18] openjpa.jdbc.SQL - <t 17368622, conn > 24437939> [0 ms] spent > 3625 parkPU TRACE [qtp33344123-18] openjpa.jdbc.SQL - <t 17368622, conn > 27529215> executing prepstmnt 15554028 SELECT t1.id, t1.p_type, > t1.version, t1.address, t1.name, t0.dt_foundation, t0.taxpayers_id FROM > park.legal_entity t0 INNER JOIN park.person t1 ON t0.person_id = t1.id > WHERE t1.p_type = ? [params=(String) LE] > 3627 parkPU TRACE [qtp33344123-18] openjpa.jdbc.SQL - <t 17368622, conn > 27529215> [2 ms] spent > [Click] [info ] renderTemplate: /legalEntity.htm,/border-template.htm - > 111 ms > [Click] [info ] handleRequest: /legalEntity.htm - 4534 ms > [Click] [debug] POST http://localhost:8080/legalEntity.htm > [Click] [debug] Form -> LegalEntity.name : Gilberto > [Click] [debug] Form -> LegalEntity.address : rua tal > [Click] [debug] Form -> LegalEntity.dtFoundation : Thu May 13 00:00:00 > BRT 2010 > [Click] [debug] Form -> LegalEntity.taxpayersId : 1135sdfs > 191 parkPU INFO [qtp33344123-22] openjpa.Runtime - Starting OpenJPA > 2.0.0 > 696 parkPU TRACE [qtp33344123-22] openjpa.jdbc.SQL - <t 11570087, conn > 10530939> executing prepstmnt 17464288 SELECT SEQUENCE_SCHEMA, > SEQUENCE_NAME FROM INFORMATION_SCHEMA.SEQUENCES > 696 parkPU TRACE [qtp33344123-22] openjpa.jdbc.SQL - <t 11570087, conn > 10530939> [0 ms] spent > [Click] [error] handleException: <openjpa-2.0.0-r422266:935683 nonfatal > user error> org.apache.openjpa.persistence.InvalidStateException: Can only > perform operation while a transaction is active. > at > org.apache.openjpa.kernel.BrokerImpl.assertTransactionOperation(BrokerImpl.j ava:4595) > at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1470) > at > org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:925) > at > org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.ja va:559) > at park.web.page.LegalEntityPage.onOkClicked(LegalEntityPage.java:99) > 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:616) > at org.apache.click.util.ClickUtils.invokeListener(ClickUtils.java:1749) > at > org.apache.click.util.ActionListenerAdaptor.onAction(ActionListenerAdaptor.j ava:59) > at > org.apache.click.ActionEventDispatcher.fireActionEvent(ActionEventDispatcher .java:247) > at > org.apache.click.ActionEventDispatcher.fireActionEvents(ActionEventDispatche r.java:192) > at > org.apache.click.ActionEventDispatcher$EventHolder.fireActionEvents(ActionEv entDispatcher.java:432) > at > org.apache.click.ActionEventDispatcher.fireActionEvents(ActionEventDispatche r.java:225) > at > org.apache.click.ActionEventDispatcher.fireActionEvents(ActionEventDispatche r.java:211) > at org.apache.click.ClickServlet.performOnProcess(ClickServlet.java:637) > at org.apache.click.ClickServlet.processPage(ClickServlet.java:533) > at org.apache.click.ClickServlet.handleRequest(ClickServlet.java:363) > at org.apache.click.ClickServlet.doPost(ClickServlet.java:283) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) > at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:530) > at > org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:427) > at > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119 ) > at > org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:494) > at > org.eclipse.jetty.server.session.SessionHandler.handle(SessionHandler.java:1 82) > at > org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java :933) > at > org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:362) > at > org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java: 867) > at > org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117 ) > at > org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHand lerCollection.java:245) > at > org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection. java:126) > at > org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:1 13) > at org.eclipse.jetty.server.Server.handle(Server.java:334) > at > org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:55 9) > at > org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnectio n.java:1007) > at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:747) > at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:209) > at > org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:406) > at > org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.jav a:462) > at > org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:4 36) > at java.lang.Thread.run(Thread.java:636) > [Click] [info ] renderTemplate: /click/error.htm - 72 ms > [Click] [info ] handleRequest: /legalEntity.htm - 1140 ms > > That's my code: > public boolean onOkClicked() { > if (form.isValid()) { > LegalEntity legalEntity = new LegalEntity(); > form.copyTo(legalEntity); > > getEntityManager().getTransaction().begin(); > getEntityManager().persist(legalEntity); > getEntityManager().getTransaction().commit(); //at > park.web.page.LegalEntityPage.onOkClicked(LegalEntityPage.java:99) > > form.clearValues(); > > msg = "A new legalEntity record has been created"; > } > return true; > } > > What does it mean? Gilberto -- View this message in context: http://openjpa.208410.n2.nabble.com/InvalidStateException-tp210537p5050893.h tml Sent from the OpenJPA Users mailing list archive at Nabble.com.
