-->
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: NHibernate.UnresolvableObjectException using Discriminators
PostPosted: Tue Apr 04, 2006 5:04 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Intro
I have RoutePath class, which includes 1-N RoutePoints. There are 2 types of points: RoutePoint and ExtraRoutePoint (using Discriminator)

Both Point classes implement IRoutePoint interface, and inherit BaseRoutePoint class:

interface IRoutePoint {
float DestX { get; set; }
float DestY { get; set; }
}

class BaseRoutePoint:IRoutePoint {
....
}

class RoutePoint:BaseRoutePoint {
....
}

class ExtraRoutePoint:BaseRoutePoint {
....
}

and RoutePath class definition:

class RoutePath {
....
// this should be either RoutePoint or ExtraRoutePoint
public IRoutePoint DestPointId {
}
}


tables
table Dest_Point
---------------------
Dest_Point_Id | Dest_Type_Id | Dest_X | Dest_Y

table Route_Path
Route_Path_Id | Dest_Point_Id

one-to-many FK


Question:
How do I achieve wanted results (I probably need to change RoutePath mapping file) so RoutePath can have either RoutePoint or ExtraRoutePoint? Give me some clues, please, I'm quite stuck with it.

below there are mapping files (truncated, but they should give you the clue)




Hibernate version:
1.0.2
Mapping documents:

RoutePoint Mapping:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="true" default-access="nosetter.pascalcase-m-underscore">
<class name="My.Data.RoutePoint, My.Data" table="Dest_Point" lazy="true" mutable="true" discriminator-value="2">
<id name="Id" unsaved-value="0" column="Dest_Point_Id" type="System.Int32">
<generator class="native"/>
</id>
<discriminator column="Dest_Type_Id" type="System.Int32" force="true" />
<property name="DestX" column="Dest_X" type="System.Single" not-null="true" />
<property name="DestY" column="Dest_Y" type="System.Single" not-null="true" />
</class>
</hibernate-mapping>

ExtraRoutePoint mapping

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="true" default-access="nosetter.pascalcase-m-underscore">
<class name="My.Data.ExtraRoutePoint, My.Data" table="Dest_Point" lazy="true" mutable="true" discriminator-value="1">
<id name="Id" unsaved-value="0" column="Dest_Point_Id" type="System.Int32">
<generator class="native"/>
</id>
<discriminator column="Dest_Type_Id" type="System.Int32" force="true" />
<property name="Name" column="Dest_Name" not-null="true" type="System.String" />
<property name="Description" column="Dest_Desc" not-null="true" type="System.String" />
<property name="DestX" column="Dest_X" type="System.Single" not-null="true" />
<property name="DestY" column="Dest_Y" type="System.Single" not-null="true" />
</class>
</hibernate-mapping>


RoutePath mapping:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="true" default-access="nosetter.pascalcase-m-underscore">
<class name="My.Data.RoutePath, My.Data" table="Route_Path" lazy="true" mutable="true">
<id name="Id" unsaved-value="0" column="Route_Path_Id" type="System.Int32">
<generator class="native"/>
</id>

<many-to-one name="DestPointId" column="Dest_Point_ID" fetch="select" cascade="none" class="What class name should I put here?, My.Data" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 9:03 am 
Newbie

Joined: Thu Dec 01, 2005 5:11 am
Posts: 16
Location: Estonia
Found my own solution here:
http://www.theserverside.net/articles/s ... NHibernate

I just did not know how to use subclassing properly :D


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhRegistration.Person, nhRegistration" table="people">
<id name="Id" column="personid" type="Int32">
<generator class="assigned" />
</id>
<discriminator column="persontype" type="String"/>
<property name="FirstName" column="firstname"
type="String(50)"/>
<property name="LastName" column="lastname"
type="String(50)"/>
<subclass name="nhRegistration.Professor, nhRegistration"
discriminator-value="professor">
<property name="Identifier" column="identifier"
type="String"/>
</subclass>
<subclass name="nhRegistration.Student, nhRegistration"
discriminator-value="student">
<property name="SSN" column="identifier"
type="String"/>
</subclass>
</class>
</hibernate-mapping>


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.