No row with the given identifier exists

I've recently gotten this infamous Exception while doing a HQL query.
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [it.linksystem.csai.model.Operator#3]

This was rather strange as the system worked quite well and it successfully retrieved selects on that entity using the Criteria API.
Looking on the net, most suggestions and FAQ's point to a different direction. My issue was rather simple mapping error. The entity on which I was doing selects, was referencing an Operator. In my (java) model, Admin inherits from Operator, and both inherit from User. In fact persisting the entities was no problem no matter if the entity persisted was referencing an Admin or Operator. If however there was an instance that referenced an Admin hibernate would launch the Exception if one executed a HQL query (I guess Criteria queries follow a different path to create the select and are immune to this issue).
My mistake was that I didn't know you can nest a subclass tag in another subclass tag in the hbm file so I've put all subclasses directly under User. Once I've moved Admin under Operator the HQL works fine.
I hope this will help somebody.

Comments

Unknown said…
Thanks! I have passed four days searching for this problem. Your solution really works. Good Job!
schrepfler said…
Glad to be of any assistence :)

Popular posts from this blog

Relaxing SSL validation for JaxWS

Kaspersky Anti Virus 6 and Subversion problems

Search and Replace in ODT using AODL