Hi folks,
Sorry to unnerve everyone with this newbie stuff, but I just can't get
my Oracle persistence hibernated...
I really wanted to get something like a quickstart example working in
order to see the benefits of NH, but i fail at a very early stage.
I worked through many NH-tutorials, but the problems I have here seem
oracle-related.
I will try to put everything here in order to shed some light on my
problem.
/**********nhibernate.config**********/
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</
property>
<property
name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</
property>
<property name="connection.connection_string">Data
source=
host.name;User Id=dbuser;Password=dbpass;</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="query.substitutions">True=1;False=0</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
/**********user class**********/
namespace NHibernate.Examples.QuickStart
{
[NHibernate.Mapping.Attributes.Class(0,
Table = "users",
Schema="sc01")]
public class User
{
[
NHibernate.Mapping.Attributes.Id(0,
Column = "logonid",
Name = "logonId",
TypeType =
typeof(string),
UnsavedValue = "")]
public string logonId;
[NHibernate.Mapping.Attributes.Property(0,
Column = "name",
Name = "Name",
TypeType = typeof(string),
NotNull = true,
Length = 100)]
public string name;
}
}
/**********main**********/
namespace NHibernate.Examples.QuickStart
{
class Program
{
static void Main(string[] args)
{
try
{
NHibernate.Cfg.Configuration cfg = new
NHibernate.Cfg.Configuration();
cfg.Configure("C:\\path\\to\
\nhibernate.config");
ISessionFactory sf = cfg.BuildSessionFactory();
ISession ses = sf.OpenSession();
ITransaction ta = ses.BeginTransaction();
IList userList =
ses.CreateCriteria(typeof(User)).List();
foreach (User usr in userList)
{
Console.Out.WriteLine("Username " +
usr.name);
}
ses.Close();
}
catch (Exception e)
{
Console.Out.WriteLine(e.Message);
}
}
}
}
My Issues :
First of all, the driver resource (Oracle.DataAccess) could not be
ID'd. I have looked this up and tried to fully qualify the assembly by
adding to the app.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Oracle.DataAccess"
fullName="Oracle.DataAccess, Version=2.0.50727.42,
Culture=neutral, PublicKeyToken=89b483f429c47342" />
</assemblyBinding>
</runtime>
</assemblyBinding>
</runtime>
No use. So I copied the oracle assembly into my bin/debug directory,
which did the trick. This is very very ugly...Is there anything wrong
with what I added to app.conf? Both Version and PTK have been
delivered by the sn.exe.
Next thing, after just copying the dll :
IList userList = ses.CreateCriteria(typeof(User)).List();
gives a compiler error, since IList is generic. All tutorials I have
seen do it like that, how can this be done without getting a compiler
error? I went for a one-liner to make it easier to find the bug :
User usr = ses.Load(typeof(User), 1);
This again leads to another exception : ses.Load returns an Object
that cannot be cast implicitly, so i have to go like
User usr = (User)ses.Load(typeof(User), 1);
That, again throws "unknown entity class
NHibernate.Examples.QuickStart.User", which I fail to grasp. Any Idea?
It would be really great if someone had the time to write a line or
two.
thanks in advance,
Sebi