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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 2:59 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
Hi Friends,
I am new to the N hibernate and ORM. I have done sample application using N hibernate with the use of N hibernate in action material, But it shows me an Exception as "Could not compile the mapping document: HelloWorldNHibernate.Employee.hbm.xml" . I set the mapping xml file Build Action property as Embedded resource. Could you please clarify me whats wrong with this.

XML File As:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="NHibernateSample.Employee, NHibernateSample" lazy="false">
<id name="id" access="field">
<generator class="assigned" />
</id>
<property name="name" access="field" column="name"/>
<many-to-one access="field" name="manager" column="manager" cascade="all"/>
</class>
</hibernate-mapping>

Mapped Class:

class Employee
{
public int id;
public string name;
public Employee manager;

public string SayHello()
{
return string.Format(
"'Hello World!', said {0}.", name);
}
}

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 4:25 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
What does the inner exception say ? There seem to be an error in your XML.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 4:51 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
What does the inner exception say ? There seem to be an error in your XML.


Hi,
My inner Exception Says "Could not find the dialect in the configuration".

Thanks for your response...

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 4:59 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
In that case something with your hibernate configuration is wrong. Can you post your config file and the code where you build the session factory ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 5:04 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
In that case something with your hibernate configuration is wrong. Can you post your config file and the code where you build the session factory ?



Hi,
My Class file is,

static void Main()
{
CreateEmployeeAndSaveToDatabase();
Console.WriteLine("Press any key to exit...");

}

static void CreateEmployeeAndSaveToDatabase()
{
HelloWorldNHibernate.Employee tobin = new HelloWorldNHibernate.Employee();
tobin.name = "Tobin Harris";
using (ISession session = OpenSession())
{
using (ITransaction transaction = session.BeginTransaction())
{
session.Save(tobin);
transaction.Commit();
}
Console.WriteLine("Saved Tobin to the database");
}
}

static ISession OpenSession()
{
Configuration c = new Configuration();
c.AddAssembly(Assembly.GetCallingAssembly());
ISessionFactory f = c.BuildSessionFactory();
return f.OpenSession();
}

and my xml Config file :

<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="HelloWorldNHibernate.Employee, HelloWorldNHibernate" lazy="false">
<id name="id" access="field">
<generator class="native" />
</id>
<property name="name" access="field" column="name"/>
<many-to-one access="field" name="manager" column="manager" cascade="all"/>
</class>
</hibernate-mapping>


And App.config File :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System,
Version=1.0.3300.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<nhibernate>
<add key="hibernate.show_sql"
value="false" />
<add key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.connection.connection_string"
value="Data Source=DTDB;Initial Catalog=PPO_DEV;Integrated Security=SSPI;" />
</nhibernate>
</configuration>


Thanks for your Response..

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 5:15 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
If you use NHib 2.x your config should look like this (breaking changes from 1.2 to 2.0!):

Code:
<configSections>
      <section name="hibernate-configuration"
             type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
   </configSections>

   <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
      <session-factory>
         <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
         <property name="connection.connection_string">
            Server=(local);initial catalog=theDb;Integrated Security=SSPI
         </property>
         <property name="connection.isolation">ReadCommitted</property>

         <property name="proxyfactory.factory_class">
            NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
         </property>
      </session-factory>
   </hibernate-configuration>

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 5:30 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
If you use NHib 2.x your config should look like this (breaking changes from 1.2 to 2.0!):

Code:
<configSections>
      <section name="hibernate-configuration"
             type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
   </configSections>

   <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
      <session-factory>
         <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
         <property name="connection.connection_string">
            Server=(local);initial catalog=theDb;Integrated Security=SSPI
         </property>
         <property name="connection.isolation">ReadCommitted</property>

         <property name="proxyfactory.factory_class">
            NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
         </property>
      </session-factory>
   </hibernate-configuration>



Hi,
I hace placed the above code in my app.config section, It shows me an exception like
App.config file is invalid. There are multiple root elements. Whether i need to define as Nhibernate, Because i am using Nhibernate with c#.net

Thanks for your response..

_________________
Thanks & Regards
Nizam Abdul


Last edited by mummu on Fri Aug 28, 2009 5:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 5:34 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
This part should go into the <configuration>...</configuration> block !

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 5:44 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
This part should go into the <configuration>...</configuration> block !


Hi,
After I change <Nhibernate-Configuration> instead of hibernate, i got an another exception "The type initializer for 'NHibernate.Cfg.Environment' threw an exception." And the inner exception says "Configuration system failed to initialize".
When I kept hibernate section it shows me exception "Could not compile Mapping file."

Thanks for your valuable response..

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 5:55 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can u post the new config file ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 6:05 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
Can u post the new config file ?


Hi,
Code:
<configuration>
<configSections>
  <section name="hibernate-configuration"
         type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<nhibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">
      Server=(dtdb);initial catalog=ppo_dev;UserId=sa; Password = master; Integrated Security=SSPI
    </property>
    <property name="connection.isolation">ReadCommitted</property>

    <property name="proxyfactory.factory_class">
      NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
    </property>
  </session-factory>
</nhibernate-configuration>
</configuration>


I am new to the Nhibernate, Could you please suggest me which book or meterial is best for Nhibernate.

Thanks for your response.

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 6:16 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
<section name="hibernate-configuration"

<nhibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

These have to have the same name (I'm not sure if nhibernate-configuration is allowed or if it has to be hibernatae-configuration - you have to try). This is not so much an issue of hibernate than of .net configuration. Execpt that "NHibernate in action is a good start" and have a look at http://www.nhforge.org.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 6:36 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
<section name="hibernate-configuration"

<nhibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

These have to have the same name (I'm not sure if nhibernate-configuration is allowed or if it has to be hibernatae-configuration - you have to try). This is not so much an issue of hibernate than of .net configuration. Execpt that "NHibernate in action is a good start" and have a look at http://www.nhforge.org.



Hi,
Again I am getting the Same Exception as i got before
"Could not compile the mapping document: HelloWorldNHibernate.Employee.hbm.xml". I have Added Nhibernate, Nhibernate.Mapping.Attributes and Log4Net dll Also. Still I am not getting .

App File

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
  <section name="hibernate-configuration"
         type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">
      Server=(dtdb);initial catalog=ppo_dev;UserId=sa; Password = master; Integrated Security=SSPI
    </property>
    <property name="connection.isolation">ReadCommitted</property>

    <property name="proxyfactory.factory_class">
      NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
    </property>
  </session-factory>
</hibernate-configuration>
</configuration>

Thank you ..

_________________
Thanks & Regards
Nizam Abdul


Last edited by mummu on Fri Aug 28, 2009 6:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 6:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Same inner exception?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Nhibernate mapping file could not complile
PostPosted: Fri Aug 28, 2009 6:58 am 
Newbie

Joined: Thu Aug 27, 2009 6:28 am
Posts: 19
wolli wrote:
Same inner exception?


Hi,
My inner Exception states that "persistent class HelloWorldNHibernate.Employee, HelloWorldNHibernate not found". But I kept Solution Name as "HelloWorldNHibernate" only.

Thanks..

_________________
Thanks & Regards
Nizam Abdul


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.