-->
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.  [ 3 posts ] 
Author Message
 Post subject: nHibernate says <discriminator> child element is inval
PostPosted: Wed Nov 07, 2007 3:39 pm 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
I'm trying to get a simple table-per-class hierarchy test working but I get an error that the <discriminator> tag is invalid. I've looked at online examples and it looks like my mapping file is correct. Any help?

Note: the object hierarchy has PhysicalDevice as an abstract base class with Firewall, Hub, and Router as classes that inherit from PhysicalDevice. One table, tblDevice, is used to persist all classes; it has a discriminator field, MyTypeName. Note2: I'm running a test to try and determine if the discriminatory column is filled in with the class name when I save a specific class -- e.g. a Router.

Hibernate version: It's 1.2.0.GA merged with the NH-466 patch (I built a custom version because I needed the 'join' tag)

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">

<class name="DomainModel.Device.PhysicalDevice, DomainModel" table="dbo.tblDevice">

<!-- Primary Key -->
<id type="Int32" column="ID" name="ID" unsaved-value="null">
<generator class="identity"></generator>
</id>

<!-- Simple properties -->
<property name="Name" column="DeviceName"/>

<!-- Inheritance: Table per class hierarchy -->
<discriminator column="MyTypeName"/>
<subclass name="DomainModel.Device.Firewall, DomainModel" discriminator-value="Firewall">
</subclass>
<subclass name="DomainModel.Device.Hub, DomainModel" discriminator-value="Hub">
</subclass>
<subclass name="DomainModel.Device.Router, DomainModel" discriminator-value="Router">
</subclass>
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
PhysicalDevice physicalDevice = new Router();
session.Save(physicalDevice);
session.Flush();

Full stack trace of any exception that occurs:

NHibernate.MappingException was unhandled by user code
Message="DAL.nHib.MapFiles.PhysicalDevice.hbm.xml(15,6): XML validation error:
The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element
'discriminator' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected:
'urn:nhibernate-mapping-2.2:property
urn:nhibernate-mapping-2.2:many-to-one urn:nhibernate-mapping-2.2:one-to-one
urn:nhibernate-mapping-2.2:component urn:nhibernate-mapping-2.2:dynamic-component
urn:nhibernate-mapping-2.2:any urn:nhibernate-mapping-2.2:map urn:nhibernate-mapping-2.2:set
urn:nhibernate-mapping-2.2:list urn:nhibernate-mapping-2.2:bag urn:nhibernate-mapping-2.2:idbag
urn:nhibernate-mapping-2.2:array urn:nhibernate-mapping-2.2:primitive-array urn:nhibernate-mapping-2.2:subclass urn:nhibernate-mapping-2.2:joined-subclass urn:nhibernate-mapping-2.2:loader urn:nhibernate-mapping-2.2:sql-insert urn:nhibernate-mapping-2.2:sql-update urn:nhibernate-mapping-2.2:sql-delete urn:nhibernate-mapping-2.2:filter'."
Source="NHibernate"
StackTrace:
at NHibernate.Cfg.Configuration.LogAndThrow(MappingException me) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 257
at NHibernate.Cfg.Configuration.ValidationHandler(Object o, ValidationEventArgs args) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 1658
at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(ValidationEventHandler eventHandler, Object sender, XmlSchemaValidationException e, XmlSeverityType severity)
at System.Xml.Schema.XmlSchemaValidator.ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, Object sender, String sourceUri, Int32 lineNo, Int32 linePos, Boolean getParticles)
at System.Xml.Schema.XsdValidator.ValidateChildElement()
at System.Xml.Schema.XsdValidator.ValidateElement()
at System.Xml.Schema.XsdValidator.Validate()
at System.Xml.XmlValidatingReaderImpl.ProcessCoreReaderEvent()
at System.Xml.XmlValidatingReaderImpl.Read()
at System.Xml.XmlValidatingReader.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlTextReader hbmReader, String name) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 1614
at NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String name) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 1644
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 490
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 527
at NHibernate.Cfg.Configuration.AddResources(Assembly assembly, IList resources, Boolean skipOrdering) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 658
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 642
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 604
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) in C:\RemoteNHibernate\src\NHibernate\Cfg\Configuration.cs:line 586
at DAL.nHib.DataAccessNHib.GetFactory() in C:\Projects\MyNHibTests\DAL\nHib\DALAccessNHib.cs:line 23
at DAL.nHib.DALNHibBase.getSession() in C:\Projects\MyNHibTests\DAL\nHib\DALNHibBase.cs:line 18
at DAL.nHib.DALNHibBase.save(Object o) in C:\Projects\MyNHibTests\DAL\nHib\DALNHibBase.cs:line 26
at DAL.nHib.DeviceDALNHib.savePhysicalDevice(PhysicalDevice physicalDevice) in C:\Projects\MyNHibTests\DAL\nHib\DeviceDALNHib.cs:line 34
at BAL.BusinessLogicTest.createAndSaveDevice(String deviceName, String deviceTypeName) in C:\Projects\MyNHibTests\BAL\BusinessLogicTest.cs:line 50
at _Default.Button_StartTest_Click(Object sender, EventArgs e) in c:\Projects\MyNHibTests\NHibTestWebSite\Default.aspx.cs:line 35
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Name and version of the database you are using: Microsoft SQL Server 2005; Version: 9.00.1406.00; Product Level: RTM; Edition: Developer Edition

Thanks,
Bill

_________________
metazone


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 4:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Move the <discriminator> tag to directly under the <id> tag and before any <property> tags.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 4:18 pm 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
Thanks very much, Karl.

_________________
metazone


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