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.  [ 7 posts ] 
Author Message
 Post subject: Trouble with <version>
PostPosted: Thu Dec 20, 2007 12:29 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 4:47 am
Posts: 25
I'm having a problem with using the <version> tag with NHibernate-1.2.1.GA-src.

The problem hovers around FlushEntities() in SessionImpl.cs:
The Version property of entry (EntityEntry entry = (EntityEntry) me.Value;) is null, and causes a NullReferenceException when the version is called to be incremented in:
Code:
object nextVersion = GetNextVersion(persister, values, entry, hasDirtyCollections, dirtyProperties);


I've got an int version property and have defined it in the mapping file as <version name="Version" column="version"/>

Any clues ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 5:50 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
How is your version property null? There shouldn't be a problem if you allow it to default to 0.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 5:35 pm 
Beginner
Beginner

Joined: Tue Jun 06, 2006 4:47 am
Posts: 25
My version property is not getting set.

NHibernate is causing an exception before returning a value to my version property.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 12:44 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Need more details. Could you post some mapping, class, and failing code? It sounds like some DDL for the table might be useful in this case, too. I have never had problems like this with <version>.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 28, 2008 10:44 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 4:47 am
Posts: 25
This has raised its head again. (In nHibernate 2.0.0.1)

The problem occurs when the version field in the (postgres) table (an integer field) has no value.
When this field is set to zero - everything works fine.

When the db field is left with no value - the 'EntityEntry.Version' field turns out to be null. But examining the propertyValues, the value of the id field is correct (not null).

This is weird, because in my business object, the version field is being set with a value of 0, and returning 0.

The mapping entry is:-
Code:
<version name="Version" column="version" unsaved-value="0" type="Int32" access="property"/>

But that has gone through many incarnations, and none of the options worked.

The only thing that has worked is to give the field a default value.
Is this how it should be ?

The problem shows itself in DefaultFlushEntityEventListener at line 320
Code:
               object nextVersion = isVersionIncrementRequired ?
                  Versioning.Increment(entry.Version, persister.VersionType, @event.Session) :
                  entry.Version; //use the current version


Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 28, 2008 7:22 pm 
Regular
Regular

Joined: Mon Mar 20, 2006 10:49 pm
Posts: 59
I see a couple of potential sources of the problem. First, it seems that version in the DB should always have a value. Second, if version in the DB does not have a value, there is an inconsistency between the table definition and the mapping, where version is defined as Int32, a non-nullable type. I believe in these situations NH will convert the null to a zero when setting the property.

_________________
Mike Abraham


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 4:03 am 
Beginner
Beginner

Joined: Tue Jun 06, 2006 4:47 am
Posts: 25
So maybe what is happening, is NHibernate is setting the version internally as null, which is correct as that's what is in the database. But it's being nice and converting the null to a zero when setting the version property in the business object.

All fair enough. The simple answer it to set a default value in the database table.
Just think that the exception should be handled better.


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