java - Grails framework method addTo throws exception on multiple invoke -
i want add subscriptions user class, invoking "addto" method, here code:
if (params.jobs == "on") { user.addtosubscriptions(category.findwhere(id: 1l)) } else { user.removefromsubscriptions(category.findwhere(id: 1l)) }
the "params" come checkboxes, user can subscribe category setting checkboxes. code above invoked when form submitted. doesn't work when user changes more 1 categories, think of same code above different params.x, this
if (params.offers == "on") { category cat = category.get(2) if (!user.subscriptions.contains(cat)) user.addtosubscriptions(category.findwhere(id: 2l))//needs long variable } else { user.removefromsubscriptions(category.findwhere(id: 2l)) }
what happens category wich first in code gets added , removed, other throw following exception:
org.hibernate.exception.genericjdbcexception: not execute jdbc batch update
edit: line in wich exception thrown 1 tho, wich makes no sense me :(
edit: exception gets thrown when want add category, wich added, doesnt removed. (thats categories not handled first in code, dont ask me why)
//reload page redirect(action: "usersettings")
what can do? please help! lot in advance! daniel
is possible trying remove category not associated user? know... user has no category id = 2 , sent params.offers == "off" ?
maybe should like:
if (params.jobs == "on") { user.addtosubscriptions(category.findwhere(id: 1l)) } else { category cat = category.get(2l) if (user.subscriptions.contains(cat)) { user.removefromsubscriptions(cat) } }
few tips: if have id, don't use:
category.findwhere(id:1l)
but:
category.get(1l)
the error thrown on line pasted, because last line of controller, after line yout transaction committed error thrown.
try adding code controller:
user.save() user.errors?.allerrors?.each { println }
this print errors happened during save.
Comments
Post a Comment