-->
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: Using NHibernateContrib 1.0.4 with NHibernate 2.0 ?
PostPosted: Mon Sep 22, 2008 8:29 am 
Newbie

Joined: Mon Sep 22, 2008 8:00 am
Posts: 3
Is it posible to use NHibernateContrib 1.0.4 with NHibernate 2.0?

I tried. But how to handle the exception:

"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.0'> wurde nicht erwartet."
==
"<hibernate-mapping xmlns='urn:nhibernate-mapping-2.0'> not expected."

Yes, i use "urn:nhibernate-mapping-2.2" (in my nhibernate-mapping.xsd), so "urn:nhibernate-mapping-2.0" seems to be wrong ...
but how to tell the HbmSerializer that he must create an "urn:nhibernate-mapping-2.2"?

Thank, Mike ...


Top
 Profile  
 
 Post subject: Hack around
PostPosted: Mon Sep 22, 2008 10:36 am 
Newbie

Joined: Mon Sep 22, 2008 8:00 am
Posts: 3
using System;
using System.IO;
using System.Reflection;
using NHibernate.Cfg;
using NHibernate.Mapping.Attributes;

namespace Foo
{
/// <summary>
/// Creates a configuration for NHibernate 2.0 using
/// the annotations of NHibernateContib 1.0.4.
/// </summary>
/// <example>
/// Configuration configuration = Configurator.Configure();
/// ISessionFactory factory = configuration.BuildSessionFactory();
/// ISession session = factory.OpenSession();
/// ...
/// </example>
class Configurator
{
/// <summary>
/// Creates the NHibernate configuation.
/// </summary>
/// <returns>
/// The NHibernate configuation.
/// </returns>
public static Configuration Configure()
{
HbmSerializer.Default.Validate = true;

string xml = BuildXML();
Configuration configuration = new Configuration();
// Use hibernate.cfg.xml to configure <hibernate-configuration>
configuration.Configure();
// Use annotations to configure <hibernate-mapping>
configuration.AddXmlString(xml);
return configuration;
}

private static string BuildXML()
{
string xml = "";

MemoryStream stream = Serialize();
foreach (byte b in stream.GetBuffer())
xml += (char)b;
stream.Close();

xml = xml.Replace("", "");
xml = xml.Replace("urn:nhibernate-mapping-2.0", "urn:nhibernate-mapping-2.2");
return xml;
}

private static MemoryStream Serialize()
{
MemoryStream stream = new MemoryStream();
HbmSerializer.Default.Serialize(stream, Assembly.GetExecutingAssembly());
stream.Position = 0;
return stream;
}
}
}


Top
 Profile  
 
 Post subject: Use NHibernate.Mapping.Attributes-for-NHibernate-2.0.0...
PostPosted: Mon Sep 22, 2008 11:28 am 
Newbie

Joined: Mon Sep 22, 2008 8:00 am
Posts: 3
Simply use NHibernate.Mapping.Attributes-for-NHibernate-2.0.0...


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.