-->
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.  [ 11 posts ] 
Author Message
 Post subject: discriminator with not string type
PostPosted: Tue Apr 11, 2006 10:02 am 
Newbie

Joined: Tue Apr 11, 2006 9:40 am
Posts: 4
Hi,

how can i use discriminator with type Int32 or Enum. I get always the MappingException

My mapping:

<class name="PersistentObjects.Term, PersistentObjects" table="Terms">
<id name="Id" type="Int32" column="ID" access="field.camelcase">
<generator class="native" />
</id>
<discriminator column="Type" type="Int32"/>
<property name="Description" column="Description" type="String" />
<subclass name="PersistentObjects.Finding, PersistentObjects" discriminator-value="0"/>
<subclass name="PersistentObjects.Keyword, PersistentObjects" discriminator-value="1"/>
<subclass name="PersistentObjects.Topic, PersistentObjects" discriminator-value="2"/>
</class>

Please help
Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 12:16 am 
Newbie

Joined: Mon Apr 03, 2006 1:38 am
Posts: 11
Can you post the exception details?


Top
 Profile  
 
 Post subject: Mapping Exception
PostPosted: Thu Apr 13, 2006 8:20 am 
Newbie

Joined: Tue Apr 11, 2006 9:40 am
Posts: 4
NHibernate.MappingException was unhandled
Message="Could not format discriminator value 'PersistentObjects.Term' to sql string using the IType NHibernate.Type.Int32Type"
Source="NHibernate"
StackTrace:
at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at Test.Program.Main(String[] args) in D:\PersistentObjects\Test\Program.cs:line 25


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 8:45 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You have to specify a discriminator value for the base class (Term).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:20 am 
Newbie

Joined: Tue Apr 11, 2006 9:40 am
Posts: 4
Thank you. It works. But now I want to specify enum as dicriminator type:

<class name="PersistentObjects.Term, PersistentObjects" table="Terms" discriminator-value="PersistentObjects.TermType.NoTerm">
<id name="Id" type="Int32" column="ID" access="field.camelcase">
<generator class="native" />
</id>
<discriminator column="Type" type="PersistentObjects.TermType, PersistentObjects"/>
<property name="Description" column="Description" type="String" />
<subclass name="PersistentObjects.Finding, PersistentObjects" discriminator-value="PersistentObjects.TermType.Finding"/>
</class>

where TermType is an enum:

namespace PersistentObjects
{
public enum TermType
{
NoTerm,
Finding,
}
}

I get the following exception:


NHibernate.MappingException was unhandled
Message="Illegal discriminator type: PersistentObjects.TermType"
Source="NHibernate"
StackTrace:
at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at Test.Program.Main(String[] args) in D:\PersistentObjects\Test\Program.cs:line 25

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 4:43 am 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
Why not just use Int32 for the discriminator type? The database column type is "integer".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 5:21 am 
Newbie

Joined: Tue Apr 11, 2006 9:40 am
Posts: 4
It's a matter of taste. I find it better not to look for a meaning of e.g. 1 in a code


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 9:59 am 
Beginner
Beginner

Joined: Wed Oct 05, 2005 5:35 am
Posts: 47
Location: France
sergey wrote:
You have to specify a discriminator value for the base class (Term).

Just a note: looks like if the discriminator type is not specified the discriminator value for the base class can be omitted. Funny thing...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 10:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, because by default the class qualified name is used as its discriminator value.


Top
 Profile  
 
 Post subject: yes,i want to know who do use enum
PostPosted: Sat Apr 29, 2006 4:13 am 
Newbie

Joined: Mon Apr 03, 2006 10:47 pm
Posts: 4
yes,i want to know who do use enum


Top
 Profile  
 
 Post subject: one doubt about descriminator column in case of int
PostPosted: Wed May 24, 2006 9:05 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
As sergy said that u need to put the descriminator value for base class i.e Term. what value it will carry.

Like for ex. I have NodeBase base class and depending on NodeType i have created two subclasses Node (with descriminator value=0) and Leaf (with descriminator value=1) what descriminator value i expect to give for my NodeBase (which is base class) !!!!! Any non existing value like 2 or -1


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