Re: Exception handling after violation of unique constraint
Well, even if i do: league = new League(); league.setName("repeated name"); I still have same problem, even without that piece of code. Everything works fine with Create/Update of entity if saveorupdate doesn't violate any constraint. On Sat, Sep 12, 2009 at 7:34 PM, Kalle Korhonen wrote: > Yes, but the problem originates from this: > if (entity.getId().longValue() == 0l) { > league.setId(null); > } > You can't make that league object a new entity just by nullifying it's > id. Try creating a new league if you need to. Later on, since the > saveOrUpdate failed, the null id causes the problem in > DefaultHibernateDAO because that object is already Hibernate's > session. > > Kalle > > On Sat, Sep 12, 2009 at 8:47 AM, Bruno Santos wrote: >> The question is i'm not trying to flush anything, i do (through DAO) >> session.saveOrUpdate, catch the exception and the only thing i do >> besides registering the error on the form is returning this (the page >> i'm at) wich causes (i guess) tapestry to query database to fill data >> for selectmodels. And, at this point i think tapestry uses the same >> session it used for the saveorupdate and "list" trys to flush if >> there's "dirty data". >> >> On Sat, Sep 12, 2009 at 3:02 AM, Kalle Korhonen >> wrote: >>> I'm using the plain hibernate Session (shadow) and the pattern works >>> great for me. But I think your problem is actually in "(don't flush >>> the >>> Session after an exception occurs)". You are doing something odd since >>> you need to nullify the id. For a new object, the id should normally >>> be null. Tapestry is already thinking it's a previously persisted >>> entity. >>> >>> Kalle >>> >>> >>> On Fri, Sep 11, 2009 at 2:30 PM, Bruno Santos wrote: >>>> Hello, >>>> >>>> Well, the reason should be that with persist in validate() i validate >>>> that the entity that's inserted doesn't conflict with any database >>>> constraint like in this case and the onsucess isn't fired wich in the >>>> case a constraint is violated it doesn't seem to make sense. >>>> >>>> Anyway, even if i use the code on the onSucess method it comes down to >>>> the same issue, the exception is thrown whenever i try to do any >>>> operation that requires hibernate (problem should be in >>>> hibernatesessionmanager, not being "clean"). >>>> >>>> One way i guess it could solve the problem is discarding the current >>>> hibernatesessionmanager, invalidate it somehow, but i don't know if >>>> that's possible. >>>> >>>> Thanks >>>> >>>> On Fri, Sep 11, 2009 at 10:15 PM, Sven Homburg >>>> wrote: >>>>> what is your reason, that you want to persist the enity >>>>> in the validation event? >>>>> >>>>> i think its more clear to persist it in the onSuccess event method >>>>> >>>>> with regards >>>>> Sven Homburg >>>>> Founder of the Chenille Kit Project >>>>> http://www.chenillekit.org >>>>> >>>>> >>>>> >>>>> >>>>> 2009/9/11 Bruno Santos >>>>> >>>>>> Thanks for your answer, i learned a bit more of tapestry. >>>>>> >>>>>> Now i have one more problem, not exactly related but in the same area. >>>>>> >>>>>> I have >>>>>> >>>>>> void onValidateForm() { >>>>>> if (entity.getId().longValue() == 0l) { >>>>>> league.setId(null); >>>>>> } >>>>>> >>>>>> System.out.println("OnValidateForm"); >>>>>> try { >>>>>> _entityDAO.persist(entity); >>>>>> } catch (RuntimeException ex) { >>>>>> leagueForm.recordError("error"); // EXCEPTION IS >>>>>> THROWN - THE TEST >>>>>> I'M DOING HITS THE UNIQUE CONSTRAINT >>>>>> } >>>>>> >>>>>> } >>>>>> >>>>>> void onFailure() { >>>
Re: Exception handling after violation of unique constraint
The question is i'm not trying to flush anything, i do (through DAO) session.saveOrUpdate, catch the exception and the only thing i do besides registering the error on the form is returning this (the page i'm at) wich causes (i guess) tapestry to query database to fill data for selectmodels. And, at this point i think tapestry uses the same session it used for the saveorupdate and "list" trys to flush if there's "dirty data". On Sat, Sep 12, 2009 at 3:02 AM, Kalle Korhonen wrote: > I'm using the plain hibernate Session (shadow) and the pattern works > great for me. But I think your problem is actually in "(don't flush > the > Session after an exception occurs)". You are doing something odd since > you need to nullify the id. For a new object, the id should normally > be null. Tapestry is already thinking it's a previously persisted > entity. > > Kalle > > > On Fri, Sep 11, 2009 at 2:30 PM, Bruno Santos wrote: >> Hello, >> >> Well, the reason should be that with persist in validate() i validate >> that the entity that's inserted doesn't conflict with any database >> constraint like in this case and the onsucess isn't fired wich in the >> case a constraint is violated it doesn't seem to make sense. >> >> Anyway, even if i use the code on the onSucess method it comes down to >> the same issue, the exception is thrown whenever i try to do any >> operation that requires hibernate (problem should be in >> hibernatesessionmanager, not being "clean"). >> >> One way i guess it could solve the problem is discarding the current >> hibernatesessionmanager, invalidate it somehow, but i don't know if >> that's possible. >> >> Thanks >> >> On Fri, Sep 11, 2009 at 10:15 PM, Sven Homburg >> wrote: >>> what is your reason, that you want to persist the enity >>> in the validation event? >>> >>> i think its more clear to persist it in the onSuccess event method >>> >>> with regards >>> Sven Homburg >>> Founder of the Chenille Kit Project >>> http://www.chenillekit.org >>> >>> >>> >>> >>> 2009/9/11 Bruno Santos >>> >>>> Thanks for your answer, i learned a bit more of tapestry. >>>> >>>> Now i have one more problem, not exactly related but in the same area. >>>> >>>> I have >>>> >>>> void onValidateForm() { >>>> if (entity.getId().longValue() == 0l) { >>>> league.setId(null); >>>> } >>>> >>>> System.out.println("OnValidateForm"); >>>> try { >>>> _entityDAO.persist(entity); >>>> } catch (RuntimeException ex) { >>>> leagueForm.recordError("error"); // EXCEPTION IS >>>> THROWN - THE TEST >>>> I'M DOING HITS THE UNIQUE CONSTRAINT >>>> } >>>> >>>> } >>>> >>>> void onFailure() { >>>> _entityDAO.abort(); >>>> System.out.println("onFailure"); >>>> } >>>> >>>> And this is working except it doesn't refresh the form with the errors >>>> i added on the onValidate >>>> >>>> When i use: >>>> >>>> Object onFailure() { >>>> _entityDAO.abort(); >>>> System.out.println("onFailure"); >>>> return this; >>>> } >>>> >>>> The following exception is thrown: >>>> >>>> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: >>>> null id in pt.hi.asianconnect.entities.League entry (don't flush the >>>> Session after an exception occurs) [at >>>> classpath:pt/hi/asianconnect/components/generated/CreateUpdateLeague.tml, >>>> line 12] >>>> at >>>> org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:62) >>>> at >>>> org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl$1.read(InternalComponentResourcesImpl.java:510) >>>> ... 119 more >>>> Caused by: org.hibernate.AssertionFailure: null id in >>>> pt.hi.asianconnect.entities.League entry (don't flush the
Fwd: Exception handling after violation of unique constraint
Hit wrong button i guess, sent message only to Sven. Sorry -- Forwarded message -- From: Bruno Santos Date: Fri, Sep 11, 2009 at 11:19 PM Subject: Re: Exception handling after violation of unique constraint First i like to thank you (both) for your patience and help. Well, not the solution i was looking for but i guess it solves some issues, totally agree with it and certainly will use it. However, It doesn't solved non checked exceptions hibernate might throw, like constraints that are forgotten, or other DML issues. And, production wise, what happens is user just staring to the page waiting for it to do something, giving some feedback and nothing happens. Isn't there a "catch all exception and present user some feedback option"? Or an option like "don't use this hibernatesessionmanager because it's invalid option"? Regards On Fri, Sep 11, 2009 at 10:58 PM, Sven Homburg wrote: > i think a good way for prevent doublettes > in you database is by using an Example-Query: > http://docs.jboss.org/hibernate/stable/core/reference/en/html/querycriteria.html#querycriteria-examples > > > with regards > Sven Homburg > Founder of the Chenille Kit Project > http://www.chenillekit.org > > > > > 2009/9/11 Bruno Santos >> >> Hello, >> >> Well, the reason should be that with persist in validate() i validate >> that the entity that's inserted doesn't conflict with any database >> constraint like in this case and the onsucess isn't fired wich in the >> case a constraint is violated it doesn't seem to make sense. >> >> Anyway, even if i use the code on the onSucess method it comes down to >> the same issue, the exception is thrown whenever i try to do any >> operation that requires hibernate (problem should be in >> hibernatesessionmanager, not being "clean"). >> >> One way i guess it could solve the problem is discarding the current >> hibernatesessionmanager, invalidate it somehow, but i don't know if >> that's possible. >> >> Thanks >> >> On Fri, Sep 11, 2009 at 10:15 PM, Sven Homburg >> wrote: >> > what is your reason, that you want to persist the enity >> > in the validation event? >> > >> > i think its more clear to persist it in the onSuccess event method >> > >> > with regards >> > Sven Homburg >> > Founder of the Chenille Kit Project >> > http://www.chenillekit.org >> > >> > >> > >> > >> > 2009/9/11 Bruno Santos >> > >> >> Thanks for your answer, i learned a bit more of tapestry. >> >> >> >> Now i have one more problem, not exactly related but in the same area. >> >> >> >> I have >> >> >> >> void onValidateForm() { >> >> if (entity.getId().longValue() == 0l) { >> >> league.setId(null); >> >> } >> >> >> >> System.out.println("OnValidateForm"); >> >> try { >> >> _entityDAO.persist(entity); >> >> } catch (RuntimeException ex) { >> >> leagueForm.recordError("error"); // EXCEPTION IS >> >> THROWN - THE TEST >> >> I'M DOING HITS THE UNIQUE CONSTRAINT >> >> } >> >> >> >> } >> >> >> >> void onFailure() { >> >> _entityDAO.abort(); >> >> System.out.println("onFailure"); >> >> } >> >> >> >> And this is working except it doesn't refresh the form with the errors >> >> i added on the onValidate >> >> >> >> When i use: >> >> >> >> Object onFailure() { >> >> _entityDAO.abort(); >> >> System.out.println("onFailure"); >> >> return this; >> >> } >> >> >> >> The following exception is thrown: >> >> >> >> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: >> >> null id in pt.hi.asianconnect.entities.League entry (don't flush the >> >> Session after an exception occurs) [at >> >> >> >> classpath:pt/hi/asianconnect/components/generated/CreateUpdateLeague.tml, >> >> line 12] >> >
Re: Exception handling after violation of unique constraint
Hello, Well, the reason should be that with persist in validate() i validate that the entity that's inserted doesn't conflict with any database constraint like in this case and the onsucess isn't fired wich in the case a constraint is violated it doesn't seem to make sense. Anyway, even if i use the code on the onSucess method it comes down to the same issue, the exception is thrown whenever i try to do any operation that requires hibernate (problem should be in hibernatesessionmanager, not being "clean"). One way i guess it could solve the problem is discarding the current hibernatesessionmanager, invalidate it somehow, but i don't know if that's possible. Thanks On Fri, Sep 11, 2009 at 10:15 PM, Sven Homburg wrote: > what is your reason, that you want to persist the enity > in the validation event? > > i think its more clear to persist it in the onSuccess event method > > with regards > Sven Homburg > Founder of the Chenille Kit Project > http://www.chenillekit.org > > > > > 2009/9/11 Bruno Santos > >> Thanks for your answer, i learned a bit more of tapestry. >> >> Now i have one more problem, not exactly related but in the same area. >> >> I have >> >> void onValidateForm() { >> if (entity.getId().longValue() == 0l) { >> league.setId(null); >> } >> >> System.out.println("OnValidateForm"); >> try { >> _entityDAO.persist(entity); >> } catch (RuntimeException ex) { >> leagueForm.recordError("error"); // EXCEPTION IS >> THROWN - THE TEST >> I'M DOING HITS THE UNIQUE CONSTRAINT >> } >> >> } >> >> void onFailure() { >> _entityDAO.abort(); >> System.out.println("onFailure"); >> } >> >> And this is working except it doesn't refresh the form with the errors >> i added on the onValidate >> >> When i use: >> >> Object onFailure() { >> _entityDAO.abort(); >> System.out.println("onFailure"); >> return this; >> } >> >> The following exception is thrown: >> >> Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: >> null id in pt.hi.asianconnect.entities.League entry (don't flush the >> Session after an exception occurs) [at >> classpath:pt/hi/asianconnect/components/generated/CreateUpdateLeague.tml, >> line 12] >> at >> org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:62) >> at >> org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl$1.read(InternalComponentResourcesImpl.java:510) >> ... 119 more >> Caused by: org.hibernate.AssertionFailure: null id in >> pt.hi.asianconnect.entities.League entry (don't flush the Session >> after an exception occurs) >> at >> org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:78) >> at >> org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:187) >> at >> org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:143) >> at >> org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219) >> at >> org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99) >> at >> org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58) >> at >> org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996) >> at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1589) >> at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306) >> at DefaultHibernateDAO.findByCriteria(DefaultHibernateDAO.java:104) >> >> >> The abort method from DAO was an experiment of mine wich calls >> hibernatesessionmanager.abort(). From what i understand, what happens >> is when the page is to be renderered, the hibernatesessionmanager >> that's used has "dirty" data that's why it uses >> SessionImpl.autoFlushIfRequired when i'm fetching data to refill the >> page, hence my experiment on calling the abort from >> hibernatesessionmanger, still this doesn't do it
Exception handling after violation of unique constraint
Thanks for your answer, i learned a bit more of tapestry. Now i have one more problem, not exactly related but in the same area. I have void onValidateForm() { if (entity.getId().longValue() == 0l) { league.setId(null); } System.out.println("OnValidateForm"); try { _entityDAO.persist(entity); } catch (RuntimeException ex) { leagueForm.recordError("error"); // EXCEPTION IS THROWN - THE TEST I'M DOING HITS THE UNIQUE CONSTRAINT } } void onFailure() { _entityDAO.abort(); System.out.println("onFailure"); } And this is working except it doesn't refresh the form with the errors i added on the onValidate When i use: Object onFailure() { _entityDAO.abort(); System.out.println("onFailure"); return this; } The following exception is thrown: Caused by: org.apache.tapestry5.ioc.internal.util.TapestryException: null id in pt.hi.asianconnect.entities.League entry (don't flush the Session after an exception occurs) [at classpath:pt/hi/asianconnect/components/generated/CreateUpdateLeague.tml, line 12] at org.apache.tapestry5.internal.bindings.PropBinding.get(PropBinding.java:62) at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl$1.read(InternalComponentResourcesImpl.java:510) ... 119 more Caused by: org.hibernate.AssertionFailure: null id in pt.hi.asianconnect.entities.League entry (don't flush the Session after an exception occurs) at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:78) at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:187) at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:143) at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219) at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99) at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58) at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:996) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1589) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306) at DefaultHibernateDAO.findByCriteria(DefaultHibernateDAO.java:104) The abort method from DAO was an experiment of mine wich calls hibernatesessionmanager.abort(). From what i understand, what happens is when the page is to be renderered, the hibernatesessionmanager that's used has "dirty" data that's why it uses SessionImpl.autoFlushIfRequired when i'm fetching data to refill the page, hence my experiment on calling the abort from hibernatesessionmanger, still this doesn't do it and i don't know how to "clean" data from the sessionmanager. Ideas anyone? One importante note, the test i'm doing implies that the my method that saveOrUpdate the entity is "hitting" a unique constraint On Thu, Sep 10, 2009 at 11:20 PM, Kalle Korhonen wrote: > You should instead try storing it onValidate. If it fails, you should > record an error and if it succeeds you should commit only in onSuccess > (but the method body can be otherwise empty). > > Kalle > > > On Thu, Sep 10, 2009 at 2:55 PM, Bruno Santos wrote: >> Good evening, >> >> I have a form using a zone and i have @CommitAfter on the >> onSubmitFromEntityForm() >> >> >> > t:value="entity.name" /> >> >> >> @CommitAfter >> Object onSubmitFromEntityForm() { >> >> try { >> entityDao.persist(entity); >> } catch (exception ex) { >> // handle exception >> } >> } >> >> altough i'm handling the exception the @CommitAfter creates a new >> exception since it tries to commit something that's not in transaction >> due to catched exception. >> >> How to deal with this? Is there a way to avoid the @CommitAfter to >> execute ... a handler i can use? I think i can remove the @CommitAfter >> but don't believe this should be first option. >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > >
Exception handling + @CommitAfter
Good evening, I have a form using a zone and i have @CommitAfter on the onSubmitFromEntityForm() @CommitAfter Object onSubmitFromEntityForm() { try { entityDao.persist(entity); } catch (exception ex) { // handle exception } } altough i'm handling the exception the @CommitAfter creates a new exception since it tries to commit something that's not in transaction due to catched exception. How to deal with this? Is there a way to avoid the @CommitAfter to execute ... a handler i can use? I think i can remove the @CommitAfter but don't believe this should be first option. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
OnEvent mixin + sending component values
Hi all, First of all, i'm sorry if this as been asked befored, i googled it, checked javadocs, guides, and some source code but i'm afraid i couldn't find the answer. I'm trying to load a select with the chenille kit onevent mixin, the thing is, the value from the component from wich the event gets fired is sent, but i need, besides that, values from others components in the form. A little example: when entity2 "changes" i need to be able to send entity1 value so i can determine what the values for entity3 select are. I though of something (don't know if i'm saying something really stupid) like using t:context in entity2 and send the value of entity1... i don't know how to do this, or how to access the context on the server side. Been banging my head for the past 3/4 nights and i could use some help on this. Thanks very much. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: getClientId returning null
Thanks for clarifying that. > Pass the component's clientside id as a context parameter to your handler > method. Is there a way, server-side, i can map the clientside id context to the component so i can know wich id is what? I'm asking this cause, using your suggestion i would have to pass more than one client id since i might have to load information on more than one component and without that mapping i wouldn't know where to put the information. Well, i guess i could try to send the name and id in context but that seems too complicated. Thiago's suggestion: > Tapestry) have a clientId parameter, so you can provide your own id instead > of letting Tapestry generate it for you. I guess this can solve your > problem. Doesn't solve the problem since, don't know why using t:clientId="country" on the tag isn't working and the id is still being generated. might be a conflict with some other component with same id, i guess, although i don't see it. On Wed, Aug 26, 2009 at 3:29 PM, Ulrich Stärk wrote: > The problem here is that you are trying to access the component's clientId > without the component being rendered (in your case from an XHR). The > clientId is only accurate after the component has rendered itself. See > http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ClientElement.html > Pass the component's clientside id as a context parameter to your handler > method. > > Uli > > On 26.08.2009 16:10 schrieb Bruno Santos: >> >> Hi all, >> >> My name is Bruno and I'm new to this mailing list and new to tapestry. >> >> I've been banging my head hard and googling (probably been using wrong >> keywords) for an answer for this, why is getClientId returning null, >> isn't it suppose to return the client id? If it ain't, is there a >> workaround? >> >> Code: >> >> �...@injectcomponent >> private Select country; >> >> �...@onevent(component = "country", value = "change") >> public JSONObject onChangeOperatorEvent(String value) { >> ... >> JSONObject finalJsonObject = new JSONObject(); >> finalJsonObject.put("clientId", country.getClientId()); >> >> return finalJsonObject; >> } >> >> >> - >> >> > t:id="country" encoder="countryEncoder" >> model="countryModel" t:mixins="ck/OnEvent" t:event="change" >> t:onCompleteCallback="handleSelectAjaxRequest"/> >> >> >> -- >> >> I tried with textfield also, same result. I guess @InjectComponent >> isn't enough. Can someone help me clarify this? >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> > > - > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
getClientId returning null
Hi all, My name is Bruno and I'm new to this mailing list and new to tapestry. I've been banging my head hard and googling (probably been using wrong keywords) for an answer for this, why is getClientId returning null, isn't it suppose to return the client id? If it ain't, is there a workaround? Code: @InjectComponent private Select country; @OnEvent(component = "country", value = "change") public JSONObject onChangeOperatorEvent(String value) { ... JSONObject finalJsonObject = new JSONObject(); finalJsonObject.put("clientId", country.getClientId()); return finalJsonObject; } - -- I tried with textfield also, same result. I guess @InjectComponent isn't enough. Can someone help me clarify this? - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org