-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: don't flush the Session after an exception occurs, how to
PostPosted: Fri Dec 11, 2009 5:07 pm 
Newbie

Joined: Wed Aug 12, 2009 11:49 am
Posts: 6
Hi,

I have too much headache on MySql and Hibernate.

Since I replaced DB2 with MySql, EJB2.1 with Hibernate, I always have different errors from Hibernate.

some times the data in hibernate session is missing before close session.

Today I met another exception:
don't flush the Session after an exception occurs

javax.ejb.TransactionRolledbackLocalException: ; nested exception is: org.hibernate.AssertionFailure: null id in com.loyaltycentral.model.Merchant entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.loyaltycentral.ejb.entity.service.ClientManagementEJBBean.getMerchantLocationTerminals(ClientManagementEJBBean.java:90)
at com.loyaltycentral.ejb.entity.service.client.EJSLocalStatelessClientManagementEJB_7b100336.getMerchantLocationTerminals(EJSLocalStatelessClientManagementEJB_7b100336.java:307)
at com.loyaltycentral.ejb.session.LoyaltyCentralEJBBean.findAllTerminalsByMerchantLocationId(LoyaltyCentralEJBBean.java:1953)
at com.loyaltycentral.ejb.session.EJSRemoteStatelessLoyaltyCentralEJB_e9271f65.findAllTerminalsByMerchantLocationId(EJSRemoteStatelessLoyaltyCentralEJB_e9271f65.java:1902)
at com.loyaltycentral.ejb.session._LoyaltyCentralEJB_Stub.findAllTerminalsByMerchantLocationId(_LoyaltyCentralEJB_Stub.java:4340)
at com.loyaltycentral.facade.LoyaltyCentral.findAllTerminalsByMerchantLocationId(LoyaltyCentral.java:679)
at com.ibm._jsp._deployLocationProgram._jspService(_deployLocationProgram.java:190)
at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:989)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:501)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:205)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:321)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at com.loyaltycentral.web.LcRequestProcessor.process(LcRequestProcessor.java:100)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:989)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:501)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:90)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:744)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)


Does anybody can help me?


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs, how to
PostPosted: Mon Dec 14, 2009 1:45 am 
Beginner
Beginner

Joined: Mon Dec 14, 2009 12:26 am
Posts: 23
http://www.google.com.au/search?q=%22don%27t+flush+the+Session+after+an+exception+occurs%22

Most likely, your app code is catching an exception from Hibernate somewhere earlier and is trying to continue using the failed Session instead of closing it and then re-trying with a new session. That is broken and will not work, as the Hibernate documentation clearly says.

Do your work within transactions and be prepared to re-try your work in a new session.


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs, how to
PostPosted: Mon Dec 14, 2009 9:41 am 
Newbie

Joined: Wed Aug 12, 2009 11:49 am
Posts: 6
ringerc wrote:
http://www.google.com.au/search?q=%22don%27t+flush+the+Session+after+an+exception+occurs%22

Most likely, your app code is catching an exception from Hibernate somewhere earlier and is trying to continue using the failed Session instead of closing it and then re-trying with a new session. That is broken and will not work, as the Hibernate documentation clearly says.

Do your work within transactions and be prepared to re-try your work in a new session.


Yes, I do.

First, I tried to insert a row within a transaction, but the row validated constaint. So I have to insert it again after I corrected it.

I used persist or merge method to insert/update a row. of course I have to flush them so that a row can be insert into database.

so what should I do if I don't use flush? which is the place I should change?


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs, how to
PostPosted: Mon Dec 14, 2009 10:28 am 
Beginner
Beginner

Joined: Mon Dec 14, 2009 12:26 am
Posts: 23
Quote:
Yes, I do.

First, I tried to insert a row within a transaction, but the row validated constaint. So I have to insert it again after I corrected it.


Yes, you do what?

Anyway ... if the row fails a constraint check, the persistence exception thrown as a result trashes your Session. You'll need to close it and re-run your work in a new session with the fixed data.

If that's not very appealing, you can always pre-check the validity of your data rather than just inserting it and praying.


Top
 Profile  
 
 Post subject: Re: don't flush the Session after an exception occurs, how to
PostPosted: Mon Dec 14, 2009 11:06 am 
Newbie

Joined: Wed Aug 12, 2009 11:49 am
Posts: 6
ringerc wrote:
Quote:
Yes, I do.

First, I tried to insert a row within a transaction, but the row validated constaint. So I have to insert it again after I corrected it.


Yes, you do what?

Anyway ... if the row fails a constraint check, the persistence exception thrown as a result trashes your Session. You'll need to close it and re-run your work in a new session with the fixed data.

If that's not very appealing, you can always pre-check the validity of your data rather than just inserting it and praying.


I mean I did my work within transaction.

I did close the session in every hibernate calling, which is in finally section.

because I used hibernate CRUD in session bean, which is CMT, so do I need to catch each exception and rollback the transaction?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.