-->
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.  [ 5 posts ] 
Author Message
 Post subject: Versioning
PostPosted: Tue Feb 24, 2004 1:46 pm 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
I have an existing database to which I am adding a hibernate 2.1 persistence layer. The database performs extensive modification logging and versioning.

In order to get hibernate versioning to work I need set the initial of version to 1. Then hibernate inserts the record with version equal to 1 and performs an update setting the version number to 2.

This creates two problems for me 1: After initial entry the version of the record is 2 instead of 1. 2: My modification log shows two versions of the record.

Since my database is already responsible for mainting version numbers it iqnores the initial value of the version on insert and sets the version number to 1 anyway. This is why I must default the value to 1 to get Hibernate versioning to work at all. It also increments the veresion number via triggers on update ignoring any new value set in the update statement.

My Question is:

Is there anyway to tell hibernate to use the version number in the where clause but not put it in the update clause and more importantly not execute the extra update statement to increment the version number after insert?

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 3:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, the problem is the useless update. Tell me:

(1) the version of Hibernate
(2) the mapping
(3) the code you use to save the object[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 4:13 pm 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
[quote="gavin"]Well, the problem is the useless update. Tell me:

(1) the version of Hibernate

version 2.1 final (12.12.2003)

(2) the mapping

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<class
name="com.netregulus.persistent.core.StrategicIssue"
table="A_STRATEGIC_ISSUE"
dynamic-update="true"
dynamic-insert="true"
>
<id
name="strategicIssueId"
type="java.lang.Long"
column="STRATEGIC_ISSUE_ID"
unsaved-value="null"
>
<generator class="native">
<param name="sequence">seq_strategic_issue</param>
</generator>
</id>
<version
name="version"
column="VERSION"
type="java.lang.Integer"
/>
<property
name="issueDate"
type="java.sql.Timestamp"
column="ISSUE_DATE"
length="7"
>
..... lots more propertes and sets

(3) the code you use to save the object

It's a struts application. I store the business objects and original session on the users session between requests. On user submission I reconnect the session and execute the following code.

session.reconnect();
tx = session.beginTransaction();
if (!session.contains(object)) // in case the object to save is new and wan't loaded by the session
session.saveOrUpdate(object);
session.flush();
tx.commit();
session.disconnect();

_________________
Arthur Fitt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 3:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Please upgrade to 2.1.3.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 3:02 pm 
Newbie

Joined: Tue Nov 25, 2003 12:26 pm
Posts: 12
gavin wrote:
Please upgrade to 2.1.3.


I don't see version 2.1.3 on the source forge download page. Do I need to build it from cvs?

_________________
Arthur Fitt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.