-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: configuration to avoid unexpected row count when deleting
PostPosted: Tue Jan 10, 2017 11:53 am 
Newbie

Joined: Thu Dec 08, 2016 11:21 am
Posts: 6
Is there any possibility to tell hibernate that we don’t want an
Code:
BatchingBatch: HHH000315: Exception executing batch [Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]
when we deleting an Entity.
In a legacy database it can happen that a trigger deletes a record before the hibernate sends the delete of the entity.
In other words: We are looking for a possibility to configure the return of executeBatch() in BatchingBatch
Code:
rowCounts = statement.executeBatch()

to SUCCESS_NO_INFO (-2) in such a case.


Top
 Profile  
 
 Post subject: Re: configuration to avoid unexpected row count when deleting
PostPosted: Tue Jan 10, 2017 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
You have 2 options:

1) You either remove the optimistic locking @Version attribute from the entity
2) You annotate the entity as follows:

Code:
@OptimisticLocking(type = OptimisticLockType.NONE)


Top
 Profile  
 
 Post subject: Re: configuration to avoid unexpected row count when deleting
PostPosted: Wed Jan 11, 2017 9:06 am 
Newbie

Joined: Thu Dec 08, 2016 11:21 am
Posts: 6
Thanks for your answer.
Unfortunately it does not work.
The annotation
Code:
@SQLDelete("DELETE FROM foo WHERE id = ?")

solves that issue (or is a workaround).
Another Expectations-class (NONE) is used in that case, where no check of rowcount happens.


Top
 Profile  
 
 Post subject: Re: configuration to avoid unexpected row count when deleting
PostPosted: Wed Jan 11, 2017 9:54 am 
Newbie

Joined: Thu Dec 08, 2016 11:21 am
Posts: 6
Additional Information:
the solution using SQLDelete - Annotaton works, because of Default 2nd parameter in @SQLDelete is ResultCheckStyle.NONE :) :
Code:
ResultCheckStyle check() default ResultCheckStyle.NONE;


Top
 Profile  
 
 Post subject: Re: configuration to avoid unexpected row count when deleting
PostPosted: Fri Mar 17, 2017 4:31 am 
Newbie

Joined: Thu Mar 16, 2017 3:09 am
Posts: 1
vlad wrote:
You have 2 options:

1) You either remove the optimistic locking @Version attribute from the entity
2) You annotate the entity as follows:

Code:
@OptimisticLocking(type = OptimisticLockType.NONE)


Code:
@OptimisticLocking(type = OptimisticLockType.NONE)
is not work.

Code:
entityManager.refresh(testEntity, LockModeType.NONE);
is work.

but refresh is bad idea. Could you tell me how to disable optimistic locking properly?


Top
 Profile  
 
 Post subject: Re: configuration to avoid unexpected row count when deleting
PostPosted: Wed May 10, 2017 1:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1630
Location: Romania
Then remove the version property if you don't need it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.