session - Hibernate ObjectNotFoundException, but object exists -
edit: error right, pay me no mind.
tl;dr: when try create link between 2 instances in service, hibernate complains 1 of them isn't found, though exists. appears have started happening after upgrading grails 2.3.8.
so, application call
tracking application. has users
, , in order know whether user available, have class called resourceavailability
:
class resourceavailability { def grailsapplication call callinstance user resource resourcestatus resourcestatus date datecreated // ... constraints, etc ... }
(there no link user resourceavailability.)
when user logs in, accepts call, or otherwise changes status, previous availability status deleted table , new status created. way can track how long has, e.g., been ready while calls waiting, or how long it's been since accepted call.
without bunch of error handling code, here's meat of call
controller's accept
action:
def accept(long id, long version) { // call stuff works fine... def callinstance = call.get(id) callinstance.accept() callinstance.save() def user = springsecurityservice.currentuser // clear out user's existing ready or busy status // todo: factor out service method resourceavailability.where { resource == user && (resourcestatus.statusdescription == "ready" || resourcestatus.statusdescription == "busy") }?.each { it.delete() } // set new status. error occurs in method. resourceavailabilityservice.setresourcestatus(user.id, 'accepted', callinstance) // redirect view }
and setresourcestatus
method:
void setresourcestatus(long userid, string resourcestatusdescription, call callinstance = null) { def resource = user.read(userid) resourcestatus resourcestatus = resourcestatus.findbystatusdescription(resourcestatusdescription) /** here's problem line **/ resourceavailability resourceavailabilityinstance = new resourceavailability ( callinstance: callinstance, resource: resource, resourcestatus: resourcestatus ).save(flush: true, failonerror: true) new resourcehistory(resourceavailabilityinstance).save(flush: true, failonerror: true) }
the exception occurs when trying save new resourceavailability
. (if remove flush: true
, occurs @ end of method when transaction commits.)
for reference, here exception:
error errors.grailsexceptionresolver - objectnotfoundexception occurred when processing request: [get] /calllog/call/accept/17779 no row given identifier exists: [com.foobar.calls.user#0]. stacktrace follows:
this appears have occurred when upgraded grails 2.2.0 2.3.8. still have 2.2.0 version , same code works there.
the user
(aka resource) i'm referencing definitely exists. not occurring during unit test; i'm running app , logging in. it's when calling method hibernate seems lose track of user.
i've machined code, , user instance exists inside of service, both before , after new resourceavailability
line.
edit ran method again sql logging on, , noticed this:
2014-05-29 16:10:23,806 [http-bio-8080-exec-7] debug hibernate.sql - insert resource_availability (version, call_instance_id, date_created, resource_id, resource_status_id) values (?, ?, ?, ?, ?) 2014-05-29 16:10:23,807 [http-bio-8080-exec-7] trace sql.basicbinder - binding parameter [1] [bigint] - 0 2014-05-29 16:10:23,807 [http-bio-8080-exec-7] trace sql.basicbinder - binding parameter [2] [bigint] - 17779 2014-05-29 16:10:23,808 [http-bio-8080-exec-7] trace sql.basicbinder - binding parameter [3] [timestamp] - thu may 29 16:10:23 cdt 2014 2014-05-29 16:10:23,808 [http-bio-8080-exec-7] trace sql.basicbinder - binding parameter [4] [bigint] - 30 2014-05-29 16:10:23,808 [http-bio-8080-exec-7] trace sql.basicbinder - binding parameter [5] [bigint] - 1 2014-05-29 16:10:23,826 [http-bio-8080-exec-7] debug hibernate.sql - select user0_.id id24_0_, user0_.version version24_0_, user0_.account_expired account3_24_0_, user0_.account_locked account4_24_0_, user0_.enabled enabled24_0_, user0_.first_name first6_24_0_, user0_.last_name last7_24_0_, user0_.`password` password8_24_0_, user0_.password_expired password9_24_0_, user0_.resource_level_id resource10_24_0_, user0_.username username24_0_ user user0_ user0_.id=? 2014-05-29 16:10:23,826 [http-bio-8080-exec-7] trace sql.basicbinder - binding parameter [1] [bigint] - 0
why select
after insert, , why using user.id
of 0???
edit upgraded grails hibernate plugin 3.6.10.15. didn't fix issue :/
sure enough: had added callcompleteduser
field not populated it, , in 2.3.8 default value 0 instead of null. so, hibernate complaining not being able find user id 0.
Comments
Post a Comment