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.  [ 2 posts ] 
Author Message
 Post subject: nullable enums ?
PostPosted: Thu Dec 14, 2006 5:23 pm 
Newbie

Joined: Fri May 26, 2006 3:05 pm
Posts: 4
NHibernate Beta 1.2.0 Beta2

Oracle 10g

We are having issues retrieving enum values when we mark the enum as nullable in our object. It seems that NHibernate cannot handle nullable enums, or that my mapping is incorrect. Can someone verify either way.

In the example NHibernate throws a mapping exception when we attempt to load an instance of the Person object. If we remove the "?" from the Gender on Person all is fine. What should we do to use nullable enums?

simple example

public enum GenderType : int
{
Male = 1,
Female = 2
}

public class Person
{
string _name;
GenderType? _gender;
int _id;
public virtual int Id
{
get { return _id; }
protected set { _id = value; }
}
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
public virtual GenderType? Gender
{
get { return _gender; }
set { _gender = value; }
}
}

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="Person" table="Person">

<id column="PersonID" type="Int32" name="Id">
<generator class="NHibernate.Id.SequenceGenerator">
<param name="sequence">Person_S</param>
</generator>
</id>

<property column="NAME" type="String" name="Name"/>
<property column="GENDER" type="Int32" name="Gender"/>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 9:13 am 
Regular
Regular

Joined: Tue Jan 03, 2006 11:43 am
Posts: 51
Location: Sweden
Let NHibernate autodetect the type of Gender. So remove type="Int32" and it should work. Personally I never specify the type attribute in the mapping files.


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