Can someone tell me whats wrong with the nhibernate config below? Using the latest ODP.NET version.
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
<property name="connection.connection_string">DATA SOURCE=Oracle2;PERSIST SECURITY INFO=True;USER ID=***;PASSWORD=*****</property>
<property name="show_sql">true</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
</session-factory>
</hibernate-configuration>
I get the following error
Error 1 Test 'ODPNETNH.Tests.GenerateSchema_Fixture.Can_generate_schema' failed: NHibernate.MappingException : Could not compile the mapping document: ODPNETNH.Mappings.Vendor.hbm.xml
----> NHibernate.HibernateException : Could not instantiate dialect class NHibernate.Dialect.Oracle9Dialect
----> System.TypeLoadException : Could not load type NHibernate.Dialect.Oracle9Dialect. Possible cause: no assembly name specified.
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName)
at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
I had quite a few problems working with NHibernate and Oracle (ODP.NET).
At the end the only thing which worked for me was to reference Oracle.DataAccess.dll ver. 2.111, specifying Copy Local = true for the DLL.
In my Nhibernate config I've used Oracle10gDialect.
Last but not least I've used this new connection-string style:
<property name="connection.connection_string">
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.1)(PORT=1522)))(CONNECT_DATA=(SERVICE_NAME=DIAP60FF)));User ID=myusername;Password=mypassword;</property>
I think I figured it out. Had to call Configure("hibernate.cfg.xml");
Related
Learning NHibernate by following this tutorial Your first NHibernate based application and I got to the point where you call
new SchemaExport(cfg).Execute(true, true, false);
in a test method to export the schema (create the Product table) for verifying NHibernate was set up correctly
[Test]
public void Can_generate_schema()
{
var cfg = new Configuration();
cfg.Configure();
cfg.AddAssembly(typeof(Product).Assembly);
new SchemaExport(cfg).Execute(true, true, false);
}
The mapping
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyFirstNHibernateProject" namespace="MyFirstNHibernateProject.Domain">
<class name="Product">
<id name="Id">
<generator class="guid"></generator>
</id>
<property name="Name"></property>
<property name="Category"></property>
<property name="Discontinued"></property>
</class>
</hibernate-mapping>
The configuration
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
<property name="connection.connection_string">Data Source=MyFirstNHibernateProject.sdf</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
The test passed and I can even see the output sql that create table but the table is not being created in the database (sql server compact), I refreshed the db in server explorer and it is still empty.
I have checked these posts
NHibernate SchemaExport not creating table
NHibernate SchemaExport does not create tables when “script” is false
NHibernate does not create Tables
but none of them solve my problem.
any ideas?
I would suggest to use full path in the connection string:
// instead of this
<property name="connection.connection_string"
>Data Source=MyFirstNHibernateProject.sdf</property>
// we should use
<property name="connection.connection_string"
>Data Source=C:\MyFirstNHibernateProject\MyFirstNHibernateProject.sdf</property>
Where the "C:\MyFirstNHibernateProject\" should be the full path to the "MyFirstNHibernateProject.sdf"
Also, in case you are suing CE 4.0 I would suggest to use this dialect:
<property name="dialect">NHibernate.Dialect.MsSqlCe40Dialect</property>
Today I updated my project to NHibernate 3.3 and replaced the NHibernate and the Iesi.Collections References.
I kept NHibernate.ByteCode.Castle
I removed the line
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> from my application config.
Now I get the error NotSupportedException in the last line of the following code:
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly(Assembly.GetExecutingAssembly());
sessionFactory = cfg.BuildSessionFactory();
I googled a lot but I don't have a clue what's wrong. And ideas? Thanks!
my config:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="connection.connection_string">Server=myserverip;Port=myport;database=my_test;User Id=my_user;Password=mypwd;CommandTimeout=1;</property>
<!--<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>-->
<property name="command_timeout">0</property>
</session-factory>
Just add this line to your xml config
<property name="hbm2ddl.keywords">none</property>
More details described here:
C# / Postgres / FluentNHibernate : configuring npgsql throws NotSupportedException
I am using Visual Studio 2005 with NHibernate-2.1.2.GA in Windows Server 2003.
I try to connect oracle with NHibernate in my ASP.net program.
To get the version of my oracle, i run this SQL : select * from v$version
The result show the oracle version is oracle9i.
So, I write NHibernate.cfg.xml like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME=MYORACLE)));
user id=team;password=team;
</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle9iDialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">10</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle
</property>
<mapping assembly="NHibernateSample.Domain"/>
</session-factory>
</hibernate-configuration>
Now, when I run the test unit which try to connect oracle and excute a query sql :
private ISession _session;
private SessionManager _helper;
private NHibernateSample _sample;
public void TestFixtureSetup()
{
_helper = new SessionManager();
}
public void Setup()
{
_session = _helper.GetSession();
_sample = new NHibernateSample(_session);
}
[NUnit.Framework.Test]
public void GetCustomerById1Test()
{
TestFixtureSetup();
Setup();
NHibernateSample _sample = new NHibernateSample(_session);
Assert.AreEqual(1, _sample.GetCustomerById(1).Id);
}
it reports errors like the following:
Test 'NHibernateSample.Data.Test.NHibernateSampleFixture.GetCustomerById1Test' failed: NHibernate.MappingException : Could not compile the mapping document: NHibernateSample.Domain.Mappings.Customer.hbm.xml
----> NHibernate.HibernateException : Could not instantiate dialect class NHibernate.Dialect.Oracle9iDialect
----> System.TypeLoadException : Could not load type org.NHibernate.Dialect.Oracle9iDialect. Possible cause: no assembly name specified.
I know that this is beginner's issue but I am just a newbie! I appreciate your ideas...
Try again removing org. from dialect
<property name="dialect">NHibernate.Dialect.Oracle9iDialect</property>
Check NHibernate SQL Dialects from official documentation for more details.
Thanks God,Finally I fix this problem.
Thers is a message in result which i forget to paste above,it's like this:
未能从程序集“mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“System.DateTimeOffset”
It's caused because my .Net2.0 version is old.
Then i install .Net2.0 SP1 and the probelm is fixed!
Thanks Claudio Redi all the same!
We're building a project using NHibernate and Castle with the Validators project. I'm trying to upgrade it to the latest supported version between all of those. I've gotten the application working without errors, but I'm getting the exception below in a few of my unit tests. These are tests that don't actually touch the database in any way, but test functionality around the mapped entities.
NHibernate.Bytecode.ProxyFactoryFactoryNotConfiguredException:
The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory
configuration section with one of the available NHibernate.ByteCode providers.
Example:
<property name='proxyfactory.factory_class'>
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
</property>
Example:
<property name='proxyfactory.factory_class'>
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
[Continues down stack trace...]
Below is my config file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="Linx2">
<property
name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="dialect">Linx2.Common.Framework.PostgreSQL83Dialect,
Linx2.Common.Framework</property>
<property name="connection.connection_string">[Hidden so I don't get fired.]</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">60</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
<property name="connection.release_mode">after_transaction</property>
<mapping assembly="NHibernate.Collection.Observable" />
</session-factory>
</hibernate-configuration>
I have the config mapping there, and it works in the application. I'm also including the NHibernate.ByteCode dll. However, in these tests it is ignored. I've tried manually starting the configuration in individual test and even stopped and confirmed mid-test that the configuration has the item. However, the exception is thrown in the code below on the IsInitialized call.
if (NHibernateUtil.IsInitialized(ChildAssociations))
{
ChildAssociations.ForEach(x => isValid = isValid && x.Element.IsValid(validatedObjects));
}
This worked previously with no problems in NHibernate build for 2.2. Any help would be greatly appreciated. I've been beating my head on it for the last 4 hours.
Apparently NHibernateUtil needs not only to have the configuration initialized, but needs the session factory to be built. I was able to get it to work by manually running the config and building the session factory in the tests. It wasn't a problem in the app because the session factory had been built before hand.
var cfg = new NHibernate.Cfg.Configuration().Configure();
var sessionFactory = cfg.BuildSessionFactory();
I'm using NHibernate with a web application and Oracle 10g XE, and I'm currently getting the following error:
ORA-06413: Connection not open.
My guess is it's a problem with my connection string. Here's my Hibernate configuration in Web.config:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="MyProject.MyAssembly">
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)));User ID=myid;Password=mypassword</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<mapping assembly="Domain" />
</session-factory>
</hibernate-configuration>
I've also tried using the following connection string:
<property name="connection.connection_string">
User ID=myid;Password=mypassword;Data Source=localhost
</property>
That resulted in the following error:
ORA-12154: TNS:could not resolve the connect identifier specified.
Could anyone provide any insight into what I might be doing wrong here?
Edit
I created a console application project inside the same solution. I created a hibernate.cfg.xml file with the same settings and added it to that project. I can persist objects with no problems.
I've switched my database from Oracle 10g to MySQL and it works fine in the web application. Why does Oracle 10g only work in the console application and not in the web application?
Apparently Oracle 10g is a bit finicky on 64-bit systems. The best option seemed to be switching to MySQL.
I faced this error today and found interesting thing.
I tried to use XE client oracle.dataaccecc.dll as reference and before the statement
sessionFactory = new NHibernate.Cfg.Configuration().Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NHibernate\\Oracle.cfg.xml")).BuildSessionFactory();
i entered these lines:
OracleConnection conn = new OracleConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
conn.Open();
conn.Close();
And everything started to work.