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.  [ 8 posts ] 
Author Message
 Post subject: When NH starts searching for hibernate.cfg.xml
PostPosted: Sat Oct 11, 2008 6:43 am 
Newbie

Joined: Thu Oct 09, 2008 9:36 am
Posts: 5
Hi,
at what point of activation does NHibernate start searching for the hibernate.cfg.xml file?

I have succeeded in configuring NHibernate without hibernate.cfg.xml in my unit tests by incorporating mapping information into an appropriate assembly, but when I use NHibernate in a windows service it complains about not being able to find the hibernate.cfg.xml.

Regards,
Dmitry.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 3:02 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
NHibernate searches for the file when you call Configure().


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 3:06 am 
Newbie

Joined: Thu Oct 09, 2008 9:36 am
Posts: 5
cremor wrote:
NHibernate searches for the file when you call Configure().


Well, I have prepared a unit test where NH configuration is stored in the App.Config file. It seems that NH does not search for hibernate.cfg.xml, but reads settings from the App.Config.

Then, I have created a windows service around the project with the same App.Config. In this case, NH does not use the App.Config but requires me to have hibernate.cfg.xml.

This is the problem. Why such a difference in behaviour?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 4:31 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hi Dmitry, I also have a windows service that uses hibernate and I use App.config. Do you have separate projects for your service and the "domain logic" ? I think in that case you have to add the App.config to your service project, not the project you call Configure() in.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 4:40 am 
Newbie

Joined: Thu Oct 09, 2008 9:36 am
Posts: 5
wolli wrote:
Hi Dmitry, I also have a windows service that uses hibernate and I use App.config. Do you have separate projects for your service and the "domain logic" ? I think in that case you have to add the App.config to your service project, not the project you call Configure() in.


Hi, Wolfgang! Thank you for your reply :)
Actually, what I have is as follows:
1. a class NHLogEntry which, as far as I understand, is a persistent class in terms of NH. The NHLogEntry lives in a separate project with the same name.
2. an auto-generated class (Log) which is in fact an ICE adapter responsible for acquiring log data from clients, instantiating NHLogEntry instances with data received and storing that data via NH using the NHLogEntry instances.

App.Config file is compiled in the NHLogEntry project. I did try compile it into the Log project as well but in vain - no result. As soon as ICE run-time instantiates the Log class the NH starts looking for the hibernate.cfg.xml file totally ignoring the App.Config.

I'm looking, actually, for another way of configuring the NH - not via a compiled-in xml files...

Regards,
Dmitry.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 5:06 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
I'm looking, actually, for another way of configuring the NH - not via a compiled-in xml files...


Why ? App.config isn't part of the assembly. Should be transformed to some xyz.exe.config and be part of your built output. And I think you also don't need to set hibernate.cfg.xml to embedded resource. Hibernate will look in the directory where the executable is.

Quote:
App.Config file is compiled in the NHLogEntry project. I did try compile it into the Log project as well but in vain - no result. As soon as ICE run-time instantiates the Log class the NH starts looking for the hibernate.cfg.xml file totally ignoring the App.Config.


So the log project contains the executable for the service ? As mentioned above, you should find a xyz.exe.config in your build directory. Try to copy that into the directory where the service is installed.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 5:33 am 
Newbie

Joined: Thu Oct 09, 2008 9:36 am
Posts: 5
wolli wrote:
Quote:
I'm looking, actually, for another way of configuring the NH - not via a compiled-in xml files...


Why ? App.config isn't part of the assembly. Should be transformed to some xyz.exe.config and be part of your built output. And I think you also don't need to set hibernate.cfg.xml to embedded resource. Hibernate will look in the directory where the executable is.

Quote:
App.Config file is compiled in the NHLogEntry project. I did try compile it into the Log project as well but in vain - no result. As soon as ICE run-time instantiates the Log class the NH starts looking for the hibernate.cfg.xml file totally ignoring the App.Config.


So the log project contains the executable for the service ? As mentioned above, you should find a xyz.exe.config in your build directory. Try to copy that into the directory where the service is installed.


Right, Wolfgang. It's my mistake - the App.Config isn't compiled into assembly. I'm sorry.

I have copied the hibernate.cfg.xml into the windows service's directory upon which everything's going OK.

Still, I'd rather have any configuration files reside next to the library I developed. If only I had access to the AppDomain into which my library gets loaded by the windows service I would be able to specify where it should look for the configs. But I don't.

Actually,
1. the windows service starts from C:\runtime folder;
2. the windows service is configured so that it looks for libraries in the D:\libs folder. The D:\libs folder is the place where the Log service and the NHLog assembly reside.

The windows service loads the assemblies OK, but refuses to load appropriate configuration files for each assembly (in my case: Log.dll.xml).

:(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 6:06 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can load the files manually:

Code:
Configuration config =                   ConfigurationManager.OpenMappedMachineConfiguration(new ConfigurationFileMap("...."));



And e.g. store the path to the config file in the registry.

_________________
--Wolfgang


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