-->
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: string as primary key
PostPosted: Wed Mar 21, 2007 10:17 am 
Newbie

Joined: Wed Mar 21, 2007 9:45 am
Posts: 3
[b]Hibernate version:[/b]

nhibernate 1.2.0

[b]Mapping documents:[/b]

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Frequentis.PCDDMS.BusinessLayer.RegisterData, Frequentis.PCDDMS.BusinessLayer" table="[RegisterData]">
<id name="Sender" column="Sender" type="String">
<generator class="assigned" />
</id>
<property column="Timestamp" name="Timestamp" type="DateTime"/>
</class>
</hibernate-mapping>

[b]Code between sessionFactory.openSession() and session.close():[/b]

RegisterData regData = new RegisterData();

regData.Sender = request.RequestSender.ToString();
regData.Timestamp = DateTime.Now;
_session.BeginTransaction(System.Data.IsolationLevel.RepeatableRead);
{
_session.Save(regData);
//_session.SaveOrUpdate(regData);
}

_session.Transaction.Commit();
_session.Flush();

[b]Name and version of the database you are using:[/b]

ms sql 2005

I have a table that contains a column for enpoints. nvarchar(50) , primary key , and a datetime column , for timestamps. i need to store the last timestamp an enpoint has send a request. when i first save an enpoint it works fine. but if the endpoint is allready in db , then , if i call update , an exception is thrown.

can u please tell me how to fix this , or an alternative.
thank you.


Top
 Profile  
 
 Post subject: Re: string as primary key
PostPosted: Wed Mar 21, 2007 11:11 am 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
Hororm wrote:
<property column="Timestamp" name="Timestamp" type="DateTime"/>

Should be... and column timestamp must be of type timestamp, not datetime.
Code:
<timestamp name="Timestamp" />

However...
SqlTeam.com wrote:
The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms.


If you want a modified date look into creating an intercepter to auto update the date on each save or update in nhibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 3:30 am 
Newbie

Joined: Wed Mar 21, 2007 9:45 am
Posts: 3
the problem is not the timestamp property. i just named it like this , but actually it is a datetime column , and the property also. the difficulties arise with the primary key.i changed the primary key to type int , and generated , and everything works fine. but i need the primary key on a string column.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 5:10 am 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
Actually what exception did you see? Post exception with full stack trace please.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.