简体   繁体   中英

Hibernate Error Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

I can't figure why I am getting this error and have been banging my head against a wall for a few hours now.

    session.beginTransaction();

    @SuppressWarnings("unchecked")
    List<ActAsUser> actAsUser = (List<ActAsUser>) session.createCriteria(ActAsUser.class)
            .add(Restrictions.eq("actAsID.userID", proxyID))
            .add(Restrictions.eq("actAsID.targetID", targetID))
            .list();

    session.delete(actAsUser.get(0));
    session.getTransaction().commit();

The code above gives me an error when trying to delete any row in the database that I have not added using Hibernate ie all the existing rows of the database that were entered through regular SQL.

Error: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

If I insert a row using Hibernate in my application I can then delete that row absolutely fine.

The thing I can't understand is that I get a user from the database first so I know that the user exists.

I've checked the Hibernate SQL and the only difference I can see is in the following when the select statement is run:

Working

/* criteria query */ select
    this_.PROXY_USER_ID as PROXY1_12_0_,
    this_.TARGET_USER_ID as TARGET2_12_0_,
    this_.EFFCT_DATE as EFFCT3_12_0_,
    this_.INCIDENT_NBR as INCIDENT4_12_0_,
    this_.TARGET_USER_NAME as TARGET5_12_0_,
    this_.EXPIRY_DATE as EXPIRY6_12_0_ 

Not Working

/* criteria query */ select
    this_.PROXY_USER_ID as PROXY1_16_0_,
    this_.TARGET_USER_ID as TARGET2_16_0_,
    this_.EFFCT_DATE as EFFCT3_16_0_,
    this_.INCIDENT_NBR as INCIDENT4_16_0_,
    this_.TARGET_USER_NAME as TARGET5_16_0_,
    this_.EXPIRY_DATE as EXPIRY6_16_0_ 

There is a difference in the numbers appended to the end of the columns, can anyone tell me what these actually mean and whether this could be the issue as this is the ONLY difference I can find between the two queries.

Just worked it out

Hibernate Query for Delete statemenet not working:

Hibernate: 
/* delete com.package.ActAsUser */ delete 
    from
        CONFIG_ACTAS_PROXY 
    where
        PROXY_USER_ID=? 
        and TARGET_USER_ID=? 
        and EFFCT_DATE=?
13:39:01,460 TRACE BasicBinder:82 - binding parameter [1] as [VARCHAR] - A534651
13:39:01,460 TRACE BasicBinder:82 - binding parameter [2] as [VARCHAR] - A512058
13:39:01,460 TRACE BasicBinder:82 - binding parameter [3] as [DATE] - 2014-11-03

PROXY_USER_ID TARGET_USER_ID EFFCT_DATE A534651 A512058 2014-11-03 04:24:44

It's the time set on the date that does it.

When adding rows through hibernate the date looks like:

2014-11-03 00:00:00

Other rows in my database look like

2014-11-03 04:24:44

When I edit them and make the time 00:00:00 the delete then works.

Changing the hibernate mapping to map to a timestamp type instead of date fixes the problem in my application too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM