Hibernate: Row was updated or deleted by another transaction

Hello, I’ve had intermittent problems creating new records using ORM in various versions of Hibernate in Lucee 5.2 & 5.3 (using Docker containers). The error only seems to show up creating NEW records.

The odd thing is Hibernate version 3.5.5.59 has not shown this error until recently and had been loading that version exclusively (since every version past this has the problem). The orm objects were originally running in CF11 and never had this issue there. I’m not sure how much code to share or if this is the correct place for this, but I’ll post some of what we’re doing. I have a base user object using the discriminator value functionality and the child objects that extend the base object. the base object has a few many-to-many relationships. Been trying to determine if I’m doing something it doesn’t like or if this in inside Hibernate.

when the error happens… none of the “role” properties are persisted, but the base objects data is okay.

Let me know what other information to provide.
Thanks, Ryan

|Message:|Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [ormObject#2959]|
|Type:|org.hibernate.StaleObjectStateException|

base object
cfcomponent persistent=“true” accessors=“true” table=“users” output=“false” discriminatorcolumn=“userType” discriminatorvalue=“user”

cfproperty name="userId" column="userId" fieldtype="id" generator="identity" ormtype="int" unsavedvalue="0">
cfproperty name="role" fieldtype="many-to-many" cfc="urRole" linktable="urUserRole" fkcolumn="userId" inversejoincolumn="roleId" lazy="false" remotingfetch="true" insert="false"

child

cfcomponent extends=“path.to.base.user” persistent=“true” accessors=“true” table=“users” discriminatorcolumn=“userType” discriminatorvalue=“fooUser”

this.ormsettings={
	datasource=this.datasource,
	cfclocation=this.ormCfc,
	dialect="MicrosoftSQLServer",
	logsql="false",
	flushatrequestend="false",
	eventHandling ="true"};

@mafimo Were you able to track down the source of this issue? What did you end up doing to solve the problem? Thanks.

that was quite awhile ago… so this may or may not be helpful. The error sounds like it could have been related to cascades so don’t trust my memory :laughing:

currently we’re using Lucee 6.2 with Ortus ORM and haven’t seen this particular problem in a long time. It might have been the commit below as that was my last change to the base component mentioned, we still use this code.

um, so about 4 months after this post I changed a property (on a database column that inserts a date via the SQL server) from

<cfproperty name="recordDate" column="recordDate" fieldtype="timestamp" generated="true" source="db" >

to

<cfproperty name="recordDate" insert="false" update="false" hint="since this is DB generated Lucee blows up with errors when we try to tell hibernate how the field works, so I removed all attributes from this property">

MSSQL table

CREATE TABLE users (
userId int IDENTITY(1,1) NOT NULL,
recordDate datetime DEFAULT (getdate()),
username varchar(50),
password varchar(67),
fname varchar(50),
lname varchar(50),
email varchar(50),
lastLogin datetime,
statusCde varchar(7),
PRIMARY KEY (userId)
);