Don’t use Default attribute on CF9 ORM persistant object primary key instead use unSavedvalue

I recently started using the CF9 along with Hibernate ORM and I had trouble saving the the object using the EntitySave Method on a new object with out setting the ForceInsert param to true.

If I don’t set the forceInsert param to true then I would get the below error which was driving me nuts since I wanted to use the EntitySave method and let CF ORM decide to save/update the object.


Exception in Hibernate operation.
Either the updated/deleted row does not exist or the session contained stale data. Root cause :o rg.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

After a lot of time googling and going through my logs I figured out that doing the following would let me use the EntitySave as I wanted.

  1. Adding the Unsavedvalue attribute to the primary key and setting it to my default ID before the object is persisted.
  2. Removing the default attribute also works.

Looks like CF9 internally uses the primary key of the object to determine if the object is persisted or not. But setting the default attribute makes the CF engine to set the value when the object is created.

I was used to setting the default attribute on my properties by practice and even the CFBuilder didn’t highlight this as an invalid attribute on the primary key which all led me to waste almost a day on this silly issue.

Hopefully this would help some one starting  off  with CF9 ORM.

No related posts.

  1. It helped me! Thank you.

  2. Thanks for the post. I’m new to Hibernate in ColdFusion (Railo, actually) and had naïvely decided to set the primary key to 0 as a default value for new ORM objects in the init() function. For example, in Person.cfc I had:

    public function init() {
    this.setPersonID(0);

    }

    in my ORM objects. This cause the error you described above.

    Thanks for the info,
    - Andrew.

  3. Thank you
    You saved my life.
    I thought I was going nuts

    Mike

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Switch to our mobile site