-->
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.  [ 8 posts ] 
Author Message
 Post subject: Version & TimeStamp
PostPosted: Mon Apr 17, 2006 8:31 pm 
Newbie

Joined: Wed Jan 25, 2006 10:53 pm
Posts: 9
Hi All,

I'm really stuck, how do I use <version> in my mapping file? I Want to use optimistic locking on SQLServer2005 but I cannot get the data from the table to the class.

The table has a column of type TimeStamp which is 8 bytes. What datatype should be the field on the class? I've tried everything I can think of Byte[], Int64 etc but they all fail as a Mapping error. I have even attempted to create my own RowVersion class to try and get the version info out.

I can cast the column as an bigint as below, so I assume that it is a int in disguise as byte[8]

SELECT CAST(Version as BIGINT)
FROM Table

Some suggestions please?

TIA

Tim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 9:51 pm 
Newbie

Joined: Wed Jan 25, 2006 10:53 pm
Posts: 9
Further to this, I have created a new class called RowVersion which decends/implements ImmutableType, IType and IVersionType. I have the very basic stuf working, I can session.Load my object with the correct "TimeStamp" value. The problem seems to be that NHibernate wants to control this value and therefore wants to try and save it back to the DB (which causes a "Cannot update a timestamp column." error from SQL server.

Is there a way to prevent this update? I could hack the SQL when it asks me for the parameter values but that is really bad.

Any thoughts?

Tim


Top
 Profile  
 
 Post subject: No replies
PostPosted: Mon Apr 24, 2006 10:32 pm 
Newbie

Joined: Wed Jan 25, 2006 10:53 pm
Posts: 9
Is no-one else using optomistic concurrency on TimeStamp columns? Have I upset the group and nobody talking to me?

What is everybody else doing for concurrency?

Tim


Top
 Profile  
 
 Post subject: How to use version, an example:
PostPosted: Mon Apr 24, 2006 11:16 pm 
Regular
Regular

Joined: Fri Jul 29, 2005 9:46 am
Posts: 101
Hi! I do use version and with SQLServer 2005, but I use the "NHibernate autoincrement Int32 mode" example:

<version name="version" access="field" type="Int32" unsaved-value="null" />

or, inside a full class mapping

<class name="BusinessObjects.Ruta, BusinessObjects">
<id name="id" access="field">
<generator class="identity" />
</id>
<version name="version" access="field" type="Int32" unsaved-value="null" />
<property name="numero" access="field" />
<property name="nombre" access="field" />
<property name="descripcion" access="field" />
<property name="estado" access="field" />
<property name="fechaCreacion" access="field" />
<property name="fechaModificacion" access="field" />
</class>

have you read "http://www.hibernate.org/hib_docs/nhibernate/html/mapping.html#mapping-declaration-timestamp"
because I think if you want to use timestamp you should use:

<timestamp
column="timestamp_column" (1)
name="PropertyName" (2)
access="field|property|nosetter|Clas(3)sName"
unsaved-value="null|undefined|value"(4)
/>

maybe you could post some of your mapping file?


Top
 Profile  
 
 Post subject: i have one question
PostPosted: Wed May 17, 2006 2:03 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
Do u mean to say to use version i need to have database column which is of the the type identity (autoincrement column)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 11:51 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
jumping in...

Quote:
Do u mean to say to use version i need to have database column which is of the the type identity (autoincrement column)


No, the DB column for version, in this example, would be of type "Int" instead of timestamp. NH will take care of incrementing the version number if it discovers that it must update the database when you call Save() or SaveOrUpdate() on the object.

More accurately, the first time you call Save() on an object, NH will insert "0" (zero) into the DB column but ignores the value of version property. SaveOrUpdate() actually checks the "version" property to discover if it needs to update the object, and if so, will incriment the version property.

If you want to use timestamp in version (although Ints are recommended), I would think you need to set the DB column to datetime (DateTime) and not timestamp. They are subtly different.

-devon


Top
 Profile  
 
 Post subject: Concurrecny related to insertion of record
PostPosted: Thu May 18, 2006 10:26 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
How will we check the concurrency in case of insertion of new record

Like someone else has inserted the record with the name="paarag" and i want to insert the record with the same name , one gochha here is name is not unique in table we have to maintain uniqueness through NHibernate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 10:44 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
pcmedsinge,

i think we are getting away from concurrency sort of, but in instances like you descrbe, i let the database handle that by settng an index (unique) on the column. NH will throw the excepton when the index is volated (with the duplicate data) and i handle it appropriately in the catch statement.

you could use NH i suppose by doing a session.Find() using the field/property that is supposed to be unique, then if you get an object in return, you handle it in code, but i prefer to have this sort of thing in the DB.

-devon


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