-->
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.  [ 4 posts ] 
Author Message
 Post subject: configuration
PostPosted: Wed Jul 25, 2007 10:30 am 
Newbie

Joined: Tue Jul 24, 2007 6:48 pm
Posts: 4
Questions on Configuration

1) I undestand that NHibernate retrieves connection in app.config under nhibernate section. If I would like to hide the connection string, is there a way to retrieve from another source ?

2) For the mapping info (hbm.xml), I can either suply the file or the assembly. Is there a way to supply memory stream ?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 4:02 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
Re #1:

You do not have to use an app.config file to configure NHibernate. I do all of my configuration "in code".

Assumes you have a static class with a private field _nhConfiguration of NHibernate.Cfg.Configuration and a private field _nhSessionFactory of NHibernate.ISessionFactory

Code:
_nhConfiguration = new NHibernate.Cfg.Configuration();
_nhConfiguration.Properties.Add("hibernate.connection.provider", "provider string");
_nhConfiguration.Properties.Add("hibernate.dialect", "dialect string");
_nhConfiguration.Properties.Add("hibernate.connection.connection_string", "your connection string");

//blah blah more properties...

_nhConfiguration.AddAssembly("your.dll"); //the dll that contains the .hbm.xml embeded resources.

_nhSessionFactory = _nhConfiguration.BuildSessionFactory();



I use the Nini configuration library to read xml configuration files with encrypted values.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 4:04 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
Re #2:

If you have a memory stream of the hbm.xml, perhaps you could use the AddDocument method of the Configuration class. It takes an XmlDocument type, so maybe you could create one by loading the xml from your memory stream.

Never tried it, don't know if it would work, but that's my best guess.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 7:42 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Actually, there are lots 'n' lots of 'AddXxx()' methods and overloads on Configuration: AddXml(), AddXmlReader(), AddFile(), AddDirectory(), AddUrl() and, yes, AddInputStream(), which will load XML right from the Stream of your choice.

They really went nuts on configuration.


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