-->
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: Mapping multiple level inheritance hierarchy error
PostPosted: Thu Jun 25, 2009 10:51 pm 
Newbie

Joined: Mon Nov 06, 2006 3:14 pm
Posts: 4
I am trying to implement my object hierarchy in one table with the "table per class hierarchy" strategy in NHibernate. I'm getting an error with my NHibernate mapping that can be easily reproduced with a simple example. The error is:

System.NotSupportedException: Attempting to parse a null value into an sql string (column:activity0_.Type).
at NHibernate.SqlCommand.InFragment.ToFragmentString() in InFragment.cs: line 109
at NHibernate.Persister.Entity.SingleTableEntityPersister.DiscriminatorFilterFragment(String alias) in SingleTableEntityPersister.cs: line 551

I can reproduce this with the following domain classes:

public interface IActivity
{
Guid Id { get; set; }
}

public class Activity : IActivity
{
public DateTime StartTime { get; set; }
public Guid Id { get; set; }
}

public class Running : Activity
{
public string Where { get; set; }
}

public class Talking : Activity
{
public string ToWhom { get; set; }
}

And the following XML mapping:

<?xml version="1.0" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateTesting"
namespace="NHibernateTesting" >
<class name="IActivity"
lazy="false"
table="Activity"
discriminator-value="0"
abstract="true">
<id name="Id">
<generator class="guid" />
</id>
<discriminator column="Type" type="Int16" />
<subclass name="Activity"
discriminator-value="1"
abstract="true"
lazy="false">
<property name="StartTime" />
</subclass>
<subclass name="Running"
discriminator-value="2"
lazy="false"
extends="Activity">
<property name="Where" />
</subclass>
<subclass name="Talking"
discriminator-value="3"
lazy="false"
extends="Activity">
<property name="ToWhom" />
</subclass>
</class>
</hibernate-mapping>

Does anyone have an idea of what I am doing wrong?


Top
 Profile  
 
 Post subject: Re: Mapping multiple level inheritance hierarchy error
PostPosted: Mon Jun 29, 2009 10:46 am 
Newbie

Joined: Sat Mar 07, 2009 2:24 am
Posts: 9
mhedgpeth wrote:
I am trying to implement my object hierarchy in one table with the "table per class hierarchy" strategy in NHibernate. I'm getting an error with my NHibernate mapping that can be easily reproduced with a simple example. The error is:

System.NotSupportedException: Attempting to parse a null value into an sql string (column:activity0_.Type).
at NHibernate.SqlCommand.InFragment.ToFragmentString() in InFragment.cs: line 109
at NHibernate.Persister.Entity.SingleTableEntityPersister.DiscriminatorFilterFragment(String alias) in SingleTableEntityPersister.cs: line 551

I can reproduce this with the following domain classes:

public interface IActivity
{
Guid Id { get; set; }
}

public class Activity : IActivity
{
public DateTime StartTime { get; set; }
public Guid Id { get; set; }
}

public class Running : Activity
{
public string Where { get; set; }
}

public class Talking : Activity
{
public string ToWhom { get; set; }
}

And the following XML mapping:

<?xml version="1.0" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateTesting"
namespace="NHibernateTesting" >
<class name="IActivity"
lazy="false"
table="Activity"
discriminator-value="0"
abstract="true">
<id name="Id">
<generator class="guid" />
</id>
<discriminator column="Type" type="Int16" />
<subclass name="Activity"
discriminator-value="1"
abstract="true"
lazy="false">
<property name="StartTime" />
</subclass>
<subclass name="Running"
discriminator-value="2"
lazy="false"
extends="Activity">
<property name="Where" />
</subclass>
<subclass name="Talking"
discriminator-value="3"
lazy="false"
extends="Activity">
<property name="ToWhom" />
</subclass>
</class>
</hibernate-mapping>

Does anyone have an idea of what I am doing wrong?



Not sure, but maybe try the discriminator as a string type


Top
 Profile  
 
 Post subject: Re: Mapping multiple level inheritance hierarchy error
PostPosted: Mon Jun 29, 2009 10:50 am 
Newbie

Joined: Sat Mar 07, 2009 2:24 am
Posts: 9
ChevronBoyde wrote:
mhedgpeth wrote:
I am trying to implement my object hierarchy in one table with the "table per class hierarchy" strategy in NHibernate. I'm getting an error with my NHibernate mapping that can be easily reproduced with a simple example. The error is:

System.NotSupportedException: Attempting to parse a null value into an sql string (column:activity0_.Type).
at NHibernate.SqlCommand.InFragment.ToFragmentString() in InFragment.cs: line 109
at NHibernate.Persister.Entity.SingleTableEntityPersister.DiscriminatorFilterFragment(String alias) in SingleTableEntityPersister.cs: line 551

I can reproduce this with the following domain classes:

public interface IActivity
{
Guid Id { get; set; }
}

public class Activity : IActivity
{
public DateTime StartTime { get; set; }
public Guid Id { get; set; }
}

public class Running : Activity
{
public string Where { get; set; }
}

public class Talking : Activity
{
public string ToWhom { get; set; }
}

And the following XML mapping:

<?xml version="1.0" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateTesting"
namespace="NHibernateTesting" >
<class name="IActivity"
lazy="false"
table="Activity"
discriminator-value="0"
abstract="true">
<id name="Id">
<generator class="guid" />
</id>
<discriminator column="Type" type="Int16" />
<subclass name="Activity"
discriminator-value="1"
abstract="true"
lazy="false">
<property name="StartTime" />
</subclass>
<subclass name="Running"
discriminator-value="2"
lazy="false"
extends="Activity">
<property name="Where" />
</subclass>
<subclass name="Talking"
discriminator-value="3"
lazy="false"
extends="Activity">
<property name="ToWhom" />
</subclass>
</class>
</hibernate-mapping>

Does anyone have an idea of what I am doing wrong?



Not sure, but maybe try the discriminator as a string type


have look at:
viewtopic.php?t=974225


Top
 Profile  
 
 Post subject: Re: Mapping multiple level inheritance hierarchy error
PostPosted: Mon Jun 29, 2009 12:41 pm 
Newbie

Joined: Mon Nov 06, 2006 3:14 pm
Posts: 4
I crossed posted this to stack overflow and got an answer there:

http://stackoverflow.com/questions/1045 ... -per-class

Thanks,
Michael Hedgpeth


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.