How do I configure a session factory for oracle?

456 views
Skip to first unread message

George Mauer

unread,
Feb 18, 2009, 4:32:02 PM2/18/09
to Fluent NHibernate
Almost certainly a stupid question but I can't find the answer
anywhere.

In the Getting Started tutorial the database is SQLite and so his
session factory creation
is done using the SQLiteConfiguration class in the
FluentNHibernate.Cfg.Db namespace

Great! But I don't see a Configuration class for using an Oracle
database. How do I do this?

(sorry if this is a double post, I did not see it pop up and assume I
had clicked cancel by accident)

Paul Batum

unread,
Feb 18, 2009, 6:39:44 PM2/18/09
to fluent-n...@googlegroups.com
Hi George,

Given that FNH does not have an oracle configuration class, you are going to have to configure NHibernate manually, as you would if you were not using FNH.

You'll notice the Fluently.Configure method now has an overload that takes an existing NHibernate.Cfg.Configuration instance. If you create a new Configuration instance, and set it up for oracle by providing the dialect, driver, etc ( as you would normally) and then pass it into the aformentioned overload, you should then be able to follow the remainder of the getting started tutorial.

var config = new Configuration();
SetTheConfigUpForOracle(config); <-- your method
Fluently.Configure(config)
  .Mappings( //etc)
  ...

If you haven't set up nhibernate to use Oracle before it should be an easy thing to google.

Paul Batum

Paul Batum

unread,
Feb 18, 2009, 6:45:00 PM2/18/09
to fluent-n...@googlegroups.com
Alternatively, you can create an "OracleConfiguration" class based on the SqlLiteConfiguration class, and just change the settings accordingly. Then you could pass it in to the database method:

Fluently.Configure()
  .Database(OracleConfiguration.Standard)
  .Etc()

Paul Batum

Filip Kinsky

unread,
Feb 19, 2009, 2:57:12 AM2/19/09
to Fluent NHibernate
you can use configuration class for Oracle from this blog post:
http://tiredblogger.wordpress.com/2008/12/04/persistanceconfiguration-for-oraclefluent-nhibernate/

James Gregory

unread,
Feb 19, 2009, 7:05:33 AM2/19/09
to fluent-n...@googlegroups.com
Good link Filip, I didn't know that existed. It's a shame people don't submit things like that as patches.

George Mauer

unread,
Feb 19, 2009, 9:40:15 AM2/19/09
to Fluent NHibernate
For the record, I tried that class but couldn't get it working. It
has a dependency on a class that no longer exists in fluent-nhibernate
and even after fixing that I kept getting an error that FNH was
looking for classes that didn't exist in my Oracle.DataAccess class

On Feb 19, 6:05 am, James Gregory <jagregory....@gmail.com> wrote:
> Good link Filip, I didn't know that existed. It's a shame people don't
> submit things like that as patches.
>
> On Thu, Feb 19, 2009 at 7:57 AM, Filip Kinsky <fi...@filovo.net> wrote:
>
> > you can use configuration class for Oracle from this blog post:
>
> >http://tiredblogger.wordpress.com/2008/12/04/persistanceconfiguration...

James Gregory

unread,
Feb 19, 2009, 9:42:11 AM2/19/09
to fluent-n...@googlegroups.com
That's interesting. The code does look out of date actually.

Shouldn't be too difficult to derive from the PersistenceConfiguration class and create your own OracleConfiguration. I'd do it myself but I don't have oracle or really know the different options available in it's connection string.

George Mauer

unread,
Feb 19, 2009, 1:40:14 PM2/19/09
to Fluent NHibernate
I fixed it up to this: http://pastebin.com/f3704d5a9
but then is started throwing a NHibernate.HibernateException : The
IDbCommand and IDbConnection implementation in the assembly
Oracle.DataAccess could not be found error.

The solution is here:
http://tiredblogger.wordpress.com/2008/11/07/using-oracle-odp-with-nhibernate-from-a-c-class-library/
but at that point became way too much of a bother.

Interestingly, the above is not a problem when using a
hibernate.cfg.xml file

George Mauer

unread,
Feb 19, 2009, 1:56:07 PM2/19/09
to Fluent NHibernate
I fixed it up to this: http://pastebin.com/f3704d5a9
but then is started throwing a NHibernate.HibernateException : The
IDbCommand and IDbConnection implementation in the assembly
Oracle.DataAccess could not be found error.

The solution is here:
http://tiredblogger.wordpress.com/2008/11/07/using-oracle-odp-with-nhibernate-from-a-c-class-library/
but at that point became way too much of a bother.

Interestingly, the above is not a problem when using a
hibernate.cfg.xml file

David R. Longnecker

unread,
Feb 27, 2009, 2:05:12 PM2/27/09
to Fluent NHibernate
LOL, always fun to search the archives and find a discussion about
your blog post.

Re: the code in that post, Oracle.DataAccess.dll must be included with
the project and, if it's a web application, the Copy Local flag must
be set to 'true' on the reference. I never have found a better way to
get that to work. Since then, I have reworked the code and dropped a
copy to James the other day regarding another conversation going on in
this thread (http://is.gd/l8kf).

-dl

On Feb 19, 12:56 pm, George Mauer <gma...@gmail.com> wrote:
> I fixed it up to this:http://pastebin.com/f3704d5a9
> but then is started throwing aNHibernate.HibernateException : The
> IDbCommand and IDbConnection implementation in the assembly
> Oracle.DataAccess could not be found error.
>
> The solution is here:http://tiredblogger.wordpress.com/2008/11/07/using-oracle-odp-with-nh...
> > > > > >sessionfactory creation
Reply all
Reply to author
Forward
0 new messages