-->
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: Application fails to find HBM file
PostPosted: Thu Dec 23, 2010 8:49 pm 
Newbie

Joined: Thu Dec 23, 2010 8:46 pm
Posts: 1
Hi,
This is my first project using NHIbernate and I'm strugling with config issues. This is a bit long, please take a look.

This is my solution structure:
GUI - winform project
ApplicationServer.dll
DatabaseServer.dll
DataEntities.dll

The hbm files are stored in a directory in the DatabaseServer.dll (Database\Mappings)
The domain classes are in the DataEntities.dll

For now I only included only one hbm file. Its build action is set to 'Embedded Resource':

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
  assembly="DataEntities"
  namespace="Themis.DataEntities"
  xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
  <class name="Project" table="PROJECTS">
    <id name="PK" column="PK" access="nosetter.camelcase">
      <generator class="native"/>
    </id>
    <property name="Name" column="NAME"/>
    <property name="Id" column="ID"/>
    <property name="Description" column="DESCRIPTION"/>
  </class> 
</hibernate-mapping>


The application will use sdf files that the user can switch so all the configuration is done through code. This code is included in DatabaseServer.dll:
Code:
Configuration cfg = new Configuration();
   
cfg.Properties["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
cfg.Properties["dialect"] = "NHibernate.Dialect.MsSqlCeDialect";
cfg.Properties["hibernate.connection.driver_class"] = "NHibernate.Driver.SqlServerCeDriver";
cfg.Properties["hibernate.connection.connection_string"] = path;

cfg.AddAssembly(this.GetType().Assembly);
cfg.AddXmlFile("Mappings\\Project.hbm.xml"); ->> ERROR HERE
sessionFactory = cfg.BuildSessionFactory();


An error is thrown when the code is adding the hbm file:

NHibernate.MappingException: Could not configure datastore from file Mappings\Project.hbm.xml ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\Documents\my documents\Visual Studio 2010\Projects\Application\GUI\bin\Debug\Mappings\Project.hbm.xml'.

Looking in the debug folder under the GUI project, I can see that there is no Mapping folder in it. Why is NHIbernate looking for it. Its supposed to be embedded in the DatabaseServer.dll.

Thanks,
Yoav


Top
 Profile  
 
 Post subject: Re: Application fails to find HBM file
PostPosted: Tue Dec 28, 2010 4:06 pm 
Newbie

Joined: Fri Jun 11, 2010 1:48 pm
Posts: 4
The same happened to me once.

As I couldn't find a solution, I set the path to my mappings in the Web.config, and then accesed it directly on the addXML...

Of course y Had to repeat it for every class y mapped (which is quite annoying).

Regards,

Sebastian


Top
 Profile  
 
 Post subject: Re: Application fails to find HBM file
PostPosted: Tue Jan 04, 2011 3:44 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You only need one of these lines:

// if mapping file is embedded ressource
cfg.AddAssembly(this.GetType().Assembly);

// if you want to load the file from disc
cfg.AddXmlFile("Mappings\\Project.hbm.xml"); ->> ERROR HERE

_________________
--Wolfgang


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.