XML Entity support in mapping files broken
Description
Environment
Attachments
Activity

Eddie Cianci January 4, 2009 at 9:50 PM
We have a need for XML Entities defined in our own DTD used by our .hbm.xml files as described here:
http://groups.google.com/group/nhusers/browse_thread/thread/99064e92c8451d16

Fabio Maulo July 6, 2008 at 12:11 PM
We prefer to continue using xsd.
BTW the source of your workaroud will be fix in NH2.1.0Alpha1 (the actual trunk) using <typedef>.
If you use a certain UserType very often, it may be useful to define a shorter name for it. You can do this using the <typedef> element. Typedefs assign a name to a custom type, and may also contain a list of default parameter values if the type is parameterized.
<typedef class="com.mycompany.Usertypes.DefaultValueIntegerType" name="default_zero">
<param name="default">0</param>
</typedef>
<property name="priority" type="default_zero"/>
The save will be available for collection.
An example for collection will be available in:
NHibernate.Test.UserCollection.Parameterized

Gerke Geurts May 1, 2008 at 1:33 AM
The The
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="DefaultNameSpaceForThisDocument"
assembly="DefaultAssemblyForThisDocument" >
works well if all mapping info is in the same assembly. However, I have a domain assembly with entity types and a shared infrastructure assembly that defines a bunch of (at times generic) user types, e.g. for intervals and custom collections. In this case all the classes in one of the assemblies have to be mapped with full type names.

Fabio Maulo April 30, 2008 at 11:46 PM
And for the second matter, probably, is enough the use of the attribute: generic="true"
BTW there is no problem to implement it.

Fabio Maulo April 30, 2008 at 11:41 PM
The
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="DefaultNameSpaceForThisDocument"
assembly="DefaultAssemblyForThisDocument" >
Is not enough ?
Details
Details
Assignee
Reporter

Up to version 1.2.1 it was possible to define XML entities in HBM mapping files, which is useful to reduce the typing of large custom (generic collection) types. However version 2.0.0 throws the following exception when loading the same config file.
An example mapping file with XML entities:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping [
<!ENTITY domain "Agg.BusinessObjects.Persistence.UnitTests.Mocks.">
<!ENTITY end-domain ", Agg.BusinessObjects.Persistence.UnitTests">
<!ENTITY set "Agg.BusinessObjects.Persistence.Nh.UserTypes.PersistentEntitySet`1[[">
<!ENTITY end-set "]], Agg.BusinessObjects.Persistence.Nh">
]>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="dbo">
<class name="&domain;MockUserEntity&end-domain;" table="users" lazy="false">
<id name="UserId" column="user_id" type="String" length="20" access="field.camelcase-underscore">
<generator class="assigned" />
</id>
<property name="FirstName" column="first_name" type="String" length="50" not-null="true" />
<property name="LastName" column="last_name" type="String" length="50" not-null="true" />
<many-to-one name="Parent" column="parent_id" class="&domain;MockUserEntity&end-domain;" />
<set name="Children" inverse="true" cascade="save-update" access="field.camelcase-underscore"
collection-type="&set;&domain;IMockUserEntity&end-domain;&end-set;"
>
<key column="parent_id" />
<one-to-many class="&domain;MockUserEntity&end-domain;" />
</set>
</class>
</hibernate-mapping>
This results in the following exception in 2.0.0-Alpha1:
NHibernate.MappingException : Could not configure datastore from input stream Agg.BusinessObjects.Persistence.UnitTests.Mocks.MockUserEntity.hbm.xml
----> System.Xml.XmlException : DTD is prohibited in this XML document.
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 262
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 510
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 544
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 615
at Agg.BusinessObjects.Persistence.Nh.UnitTests.TempDbBuilders.TempDbBuilder.AddMappings(Assembly assembly) in C:\work\DiabetesNed\projects\authorisation\trunk\src\cs\Agg.BusinessObjects.NHibernateDao.UnitTests\TempDbBuilders\TempDbBuilder.cs:line 42
at Agg.BusinessObjects.Persistence.UnitTests.NHPersistenceTests.OnCreateSessionFactory(String sessionFactoryName) in C:\work\DiabetesNed\projects\authorisation\trunk\src\cs\Agg.BusinessObjects.NHibernateDao.UnitTests\NHPersistenceTests.cs:line 15
at Agg.BusinessObjects.Persistence.UnitTests.PersistenceTestsBase.TestFixtureSetUp() in C:\work\DiabetesNed\projects\authorisation\trunk\src\cs\Agg.BusinessObjects.NHibernateDao.UnitTests\PersistenceTestsBase.cs:line 25
--XmlException
at System.Xml.XmlCharCheckingReader.Throw(String res, String arg)
at System.Xml.XmlCharCheckingReader.Read()
at System.Xml.XsdValidatingReader.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(XmlReader hbmReader, String name) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 1509
at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 1539
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in c:\work\...\trunk\src\NHibernate\Cfg\Configuration.cs:line 501
The cause seems to be that when refactoring the XmlReader code the XmlReaderSettings that are in use to read the mapping files use the default value of true' for ProhibitDtd, rather than explicitly specifying ProhibitDtd = false to maintain backwards compatibility. (see ...\trunk\src\NHibernate\Cfg\XmlSchemas.cs, Xmlschemas.CreateXmlReaderSettings(XmlSchema)).