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.  [ 9 posts ] 
Author Message
 Post subject: Nhibernate 1.0.2 how to support timestamp ?
PostPosted: Wed Aug 23, 2006 3:51 am 
Newbie

Joined: Wed Aug 23, 2006 3:28 am
Posts: 3
public class User
{
private DateTime _version;
public User()
{
}

//timestamp
public DateTime Version
{
get { return _version; }
set { _version = value;}
}
}

in config file ,how to setting timestamp?
thank you


Top
 Profile  
 
 Post subject: Re: Nhibernate 1.0.2 how to support timestamp ?
PostPosted: Wed Aug 23, 2006 5:18 am 
Beginner
Beginner

Joined: Fri Dec 23, 2005 6:05 am
Posts: 42
guoshaohong1979 wrote:
public class User
{
private DateTime _version;
public User()
{
}

//timestamp
public DateTime Version
{
get { return _version; }
set { _version = value;}
}
}

in config file ,how to setting timestamp?
thank you


There is a <version>-Tag you can use for that. It looks like
Code:
<version name="Version" type="timestamp" />


You can also use the <timestamp>-Tag.
Code:
<timestamp name="Version" />


For further detail look here.


Top
 Profile  
 
 Post subject: Nhibernate 1.0.2 how to support timestamp ?
PostPosted: Wed Aug 23, 2006 6:43 am 
Newbie

Joined: Wed Aug 23, 2006 3:28 am
Posts: 3
you said I try to .
config file to:
<timestamp name="Version" column="Version" access="field"/>
error message:
element namespace“urn:nhibernate-mapping-2.0”into“class”。 to child element namespace“urn:nhibernate-mapping-2.0”in to“timestamp”。 not valid
I think that Nhibernate 1.0.2 not support timestamp

then I retry :
config file to:
<version name="Version" column="Version" access="field"/>
error message:
element namespace“urn:nhibernate-mapping-2.0”into“class”。 to child element namespace“urn:nhibernate-mapping-2.0”中的“version”。 not valid



help me ! thank you


Top
 Profile  
 
 Post subject: Re: Nhibernate 1.0.2 how to support timestamp ?
PostPosted: Wed Aug 23, 2006 6:58 am 
Beginner
Beginner

Joined: Fri Dec 23, 2005 6:05 am
Posts: 42
guoshaohong1979 wrote:
you said I try to .
config file to:
<timestamp name="Version" column="Version" access="field"/>
error message:
element namespace“urn:nhibernate-mapping-2.0”into“class”。 to child element namespace“urn:nhibernate-mapping-2.0”in to“timestamp”。 not valid
I think that Nhibernate 1.0.2 not support timestamp

then I retry :
config file to:
<version name="Version" column="Version" access="field"/>
error message:
element namespace“urn:nhibernate-mapping-2.0”into“class”。 to child element namespace“urn:nhibernate-mapping-2.0”中的“version”。 not valid



help me ! thank you


Hi guoshaohong1979,

sorry that was my fault. You have to place the <version> or <timestamp> tag directly beneath the <id> tag.

Example
Code:
...
    <id name="Id">
      <generator class="native" />
    </id>
    <version name="Version" column="Version" access="field" />
...


Hope that helped.

eg


Top
 Profile  
 
 Post subject: Nhibernate 1.0.2 how to support timestamp ?
PostPosted: Wed Aug 23, 2006 11:43 am 
Newbie

Joined: Wed Aug 23, 2006 3:28 am
Posts: 3
first thanks the vistors!
I try to method of above,no solve problem,
hope to have good answer
thank you!


Top
 Profile  
 
 Post subject: Re: Nhibernate 1.0.2 how to support timestamp ?
PostPosted: Wed Aug 23, 2006 11:50 am 
Beginner
Beginner

Joined: Fri Dec 23, 2005 6:05 am
Posts: 42
guoshaohong1979 wrote:
first thanks the vistors!
I try to method of above,no solve problem,
hope to have good answer
thank you!


Hmm..., can you post the complete XML please?

eg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 4:19 am 
Newbie

Joined: Wed Sep 13, 2006 4:12 am
Posts: 10
as i had the same problem: only one timestamp or version field is allowed, otherwise nhibernate throws an XmlSchemaException. The <timestamp> or <version> has to be placed directly below the <id> or <discriminator> declaration.

Example:

Code:
<id name="Id" column="id" type="Int32" unsaved-value="0">
   <generator class="assigned"/>
</id>
<version name="Eddat" column="eddat" type="Timestamp" unsaved-value="null"/>
<property column="title" type="String" name="Title" length="10" />


after the single version declaration there must not be another version or timestamp. I tried to use the timestamp for several timestamp fields (date of creation, last edit, date of delete) and ran into this...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 4:50 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
d.trilsbeek wrote:
after the single version declaration there must not be another version or timestamp. I tried to use the timestamp for several timestamp fields (date of creation, last edit, date of delete) and ran into this...


The <version> and <timestamp> have special meaning to NHIbernate, and their value is managed by NHibernate, so there is no sense of having multiple of them.

If You want to map database field of type TimeStamp, use ordinary property mapping with tyep="Timestamp"

e.g.
Code:
<property name="CreateDate" type="Timestamp" />


Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 5:03 am 
Newbie

Joined: Wed Sep 13, 2006 4:12 am
Posts: 10
i know, already did it that way. This was just the way i discovered this behavior.


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