Quantcast

Feeling stupid. "No row with the given identifier exists" error.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Feeling stupid. "No row with the given identifier exists" error.

jasenj1
I have a service that "clears" my database. It issues DomainObject.list()*.delete() on all my domain objects. At the bottom of this service method I have:
sessionFactory.currentSession.flush()
sessionFactor.currentSession.clear()

Then I have a service that reloads a bunch of data. Something like:
new MyObj(name: "foo").save(flush:true)

Next I have a service that loads data from a file and references the above objects. Something like:
def myObj = MyObj.findByName("foo")
def otherObj = new OtherObj()
otherObj.setMyObj(myObj)
otherObj.save()

I get a "No row" error when the final .save() is executed. Grails is complaining that myObj can't be found and it reports the OLD id - from before the database was cleared.

So obviously Grails/Hibernate is caching some information about the MyObj class and it is not being reset when the objects are deleted and reloaded.

What should I be doing to make sure the IDs are cleared out and reloaded?

- Jasen.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Feeling stupid. "No row with the given identifier exists" error.

Graeme Rocher-2
Are you sure MyObj is actually saved and a a validation error didn't occur?

-- 
Graeme Rocher

On Tuesday, July 24, 2012 at 6:53 PM, jasenj1 wrote:

I have a service that "clears" my database. It issues
DomainObject.list()*.delete() on all my domain objects. At the bottom of
this service method I have:
sessionFactory.currentSession.flush()
sessionFactor.currentSession.clear()

Then I have a service that reloads a bunch of data. Something like:
new MyObj(name: "foo").save(flush:true)

Next I have a service that loads data from a file and references the above
objects. Something like:
def myObj = MyObj.findByName("foo")
def otherObj = new OtherObj()
otherObj.setMyObj(myObj)
otherObj.save()

I get a "No row" error when the final .save() is executed. Grails is
complaining that myObj can't be found and it reports the OLD id - from
before the database was cleared.

So obviously Grails/Hibernate is caching some information about the MyObj
class and it is not being reset when the objects are deleted and reloaded.

What should I be doing to make sure the IDs are cleared out and reloaded?

- Jasen.



--
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Feeling stupid. "No row with the given identifier exists" error.

jasenj1
Yes. I can hit the list web page and the MyObj items are shown. But their IDs are now different than they were originally. On the initial load the items are IDed 1, 2, 3, etc. They are then deleted and reloaded. The reloaded items have IDs that start where the previous data set ended.

Somewhere Grails is holding on to the old IDs. I suspect there is a cache or session or something I need to clear, but I've tried a few things and haven't hit the right call.

- Jasen.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Feeling stupid. "No row with the given identifier exists" error.

Nicholas Wittstruck
Could this be related to your database? I guess Grails is using an automatically incremented id generated by the database. So you would have to reset this increment value. How to do this is probably database specific.

Nicholas


On 25.07.2012, at 14:49, jasenj1 wrote:

> Yes. I can hit the list web page and the MyObj items are shown. But their IDs
> are now different than they were originally. On the initial load the items
> are IDed 1, 2, 3, etc. They are then deleted and reloaded. The reloaded
> items have IDs that start where the previous data set ended.
>
> Somewhere Grails is holding on to the old IDs. I suspect there is a cache or
> session or something I need to clear, but I've tried a few things and
> haven't hit the right call.
>
> - Jasen.
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Feeling-stupid-No-row-with-the-given-identifier-exists-error-tp4632124p4632188.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Feeling stupid. "No row with the given identifier exists" error.

jasenj1
"Could this be related to your database? I guess Grails is using an automatically incremented id generated by the database. So you would have to reset this increment value. How to do this is probably database specific. "

I'm fine with the new IDs. But Grails' FindBy* is returning a record with the old ID. Somehow Grails/Hibernate needs to be told to flush whatever cache it has of the old IDs.

- Jasen.
Loading...