-->
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.  [ 2 posts ] 
Author Message
 Post subject: NHibernate Configuration gotchas
PostPosted: Tue Nov 18, 2008 3:59 pm 
Newbie

Joined: Fri Aug 11, 2006 7:49 am
Posts: 1
Folks,
I'm adding this for my future reference as much as anyone elses :-).

I've spent about 2 days trying to get nhibernate to use app.config. I had previously given up but I really need to use it for my current project so I had to dig deep.

First off, keep app.config (not appconfig.xml as some posts suggest). Also leave it as Content and not an Embedded Resource (just in case you thought otherwise).

My app.config file:

<?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.OracleDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">Data Source=XXXXXX;User Id=AAAAAAAA;Password=BBBBBB;Integrated Security=no;</property>
</session-factory>
</hibernate-configuration>
</configuration>

Things to note in the above:

1. Property name fields don't have 'nhibernate.' before them etc.
2. '<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">' is the section name. It must have this label try something else and you'll get an 'An exception occurred during configuration of persistence layer.' exception.


How to initialise:

Configuration cfg = new Configuration();
// The next line actually reads from the app.config/hibernate.cfg.xml
// but not sure how it decides. Perhaps goes for app.config and then
// hibernate.cfg.xml as the last resort?
cfg.Configure();

// Add the assembly that contains the mapping xml file (needs your class for the objects to be configured correctly).
// Note: The XML file is an embedded resource in the project.
cfg.AddAssembly("Mappings");

Hope that makes sense!!
John


Top
 Profile  
 
 Post subject: Thanks!
PostPosted: Mon Dec 22, 2008 8:57 am 
Newbie

Joined: Mon Dec 22, 2008 8:55 am
Posts: 1
I also banged my head against a wall for about 2 days, trying connect my prototype to a remote Oracle database. Your solution works for me. Thanks very much!!!


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