-->
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.  [ 4 posts ] 
Author Message
 Post subject: Save Entity back to Database from JSon -> OptimisticLocking
PostPosted: Wed Feb 15, 2017 3:13 pm 
Beginner
Beginner

Joined: Tue Oct 20, 2009 6:28 am
Posts: 20
Hello,

Recently I've found a problem that's making me crazy. We are doing a test framework that's capable of saving a database state (rows) in an hierarchical way with hibernate to Json.
That way you can do a hibernate.hbm2ddl.auto=create at the begining of the tests. Restore a database snapshot and load the data for the test from the Json.

It works great!

Except if you don't rollback after the test and tries to remerge the existing entities. The problem is that the versioning timestamp is updated to now on the first save. And you cannot remerge it because the entity on the database is newer than the one loaded from the disk. While this is not true.

The problem is that Hibernate (correctly) updated the version on the first store.

My question is. Can I enter a batch mode where this version update is not done and database is stored as is? Without modifying DB definition. Programatically.

Is there a way to resolve this problem?

Is there any utility that can load the data so I don't have to do it?

Best regards,


Top
 Profile  
 
 Post subject: Re: Save Entity back to Database from JSon -> OptimisticLocking
PostPosted: Fri Feb 24, 2017 6:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
What if you switch to numerical @Version?

Code:
@Version
private Long version;


Top
 Profile  
 
 Post subject: Re: Save Entity back to Database from JSon -> OptimisticLocking
PostPosted: Fri Feb 24, 2017 12:08 pm 
Beginner
Beginner

Joined: Tue Oct 20, 2009 6:28 am
Posts: 20
It doesn't matter. In fact this is related to this other issue I opened
viewtopic.php?f=1&t=1044040

In fact the optimistic version field is okay as timestamp. This way we track whether a version has changed and when.

But thank you for the comment.


Top
 Profile  
 
 Post subject: Re: Save Entity back to Database from JSon -> OptimisticLocking
PostPosted: Fri Feb 24, 2017 12:41 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Well, using the wall-clock time for concurrency control is always trouble. Check out this article for more info.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.