NHibernate 2.1.2 - how to disable reflection optimizer - c#

I want to disable reflection optimization (testing purposes), but i don't know where to do it. NH 2.1.2 uses hibernate-configuration in XML, and docs clearly state that this setting can not be set here. :/ I tried doing it the old App.config way with key/value pairs, no luck ...
Also, did NH 2+ version change something about reflection optimization?

Did you try
<add key="hibernate.use_reflection_optimizer" value="false" />
?
From the Hibernate Community:
I was able to set the
hibernate.use_reflection_optimizer
property in the web.config file as
follows. Note that the setting did not
work within the
hibernate-configuration section, so I
had to place it in a new nhibernate
section. The code now appears to be
working in a medium trust environment
( godaddy )
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
requirePermission="false"/>
<section name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">blahblah</property>
</session-factory>
</hibernate-configuration>
<nhibernate>
<add key="hibernate.use_reflection_optimizer" value="false" />
</nhibernate>

Related

setting up oracle native encryption in web.config file

We need to setup following properties in config file to enable native encryption of oracle
SQLNET.CRYPTO_CHECKSUM_TYPES_CLIENT = (MD5)
SQLNET.ENCRYPTION_TYPES_CLIENT = (AES256)
SQLNET.ENCRYPTION_CLIENT = required
SQLNET.CRYPTO_CHECKSUM_CLIENT = required
Below is the link where I found out it can be done through config file (search for the above properties in link page e.g. ENCRYPTION_CLIENT)
https://docs.oracle.com/cd/E63277_01/win.121/e63268/InstallManagedConfig.htm#ODPNT8164
I was not able to find any good example till now.
Can anyone provide an example or link to see how to enable encryption from config file.
In Configuration section add the below lines.
<configSections>
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
Connection String:
<add key="ConnectionString" value="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server name)(PORT=XXXX))(CONNECT_DATA=(SERVICE_NAME=service name)));" />
Add the below section under runtime section:
<oracle.manageddataaccess.client>
<version number="*">
<settings>
<setting name="sqlnet.encryption_types_client" value="aes256" />
<setting name="sqlnet.encryption_client" value="required" />
</settings>
</version>
</oracle.manageddataaccess.client>

NHibernate error: Severity Code Description Project File Line Suppression State Error Unrecognized configuration section session-factory

I am trying to connect my aplication to a sql server 2012 database, but its not working and its giving the error that appears on the title, someone could help me? here is the code:
`
<?xml version="1.0"?>
<configuration>
<!-- an ISessionFactory instance -->
<session-factory>
<!-- properties -->
<property name="connection.connection_string">
User ID=****;Password=****;Data Source=****;Initial Catalog=****;
</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<!-- mapping files -->
<mapping resource="NHibernate.Auction.Item.hbm.xml" assembly="NHibernate.Auction"/>
<mapping resource="NHibernate.Auction.Bid.hbm.xml" assembly="NHibernate.Auction"/>
</session-factory>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
`
Check the doc for more configuration examples
Chapter 23. Example: Weblog Application
here is a snippet of such setting (check the <configSections>):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Add this element -->
<configSections>
<section
name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<!-- Add this element -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>

Could not create the driver from NHibernate.Driver.OracleDataClientDriver (with copy local set to true)

I even added to app.config this little piece of config:
<qualifyAssembly partialName="Oracle.DataAccess"
fullName="Oracle.DataAccess,
Version=2.112.2.0,
Culture=neutral,
PublicKeyToken=89b483f429c47342" />
</assemblyBinding>
... with no success. What could be wrong?
Also, just to be sure that my app.config is feng shui, here it is:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.driver_class">
NHibernate.Driver.OracleDataClientDriver
</property>
<property name="connection.connection_string_name">
GuitarStore2
</property>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
</session-factory>
</hibernate-configuration>
<connectionStrings>
<add name="GuitarStore"
connectionString="****************"/>
<add name="GuitarStore2"
connectionString="****************"/>
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Oracle.DataAccess"
fullName="Oracle.DataAccess,
Version=2.112.2.0,
Culture=neutral,
PublicKeyToken=89b483f429c47342" />
</assemblyBinding>
</runtime>
</configuration>
For the record, I am using the latest Nhibernate (3.3.1), on .NET 3.5, under Windows 7 64 bit. And, with the exact same project, I encounter no exceptions on another machine, but with Windows XP.
The problem wasn't NHibernate, but the fact that the IL was generating 64 bit code, whilst using the 32 bit version of ODP, so by simply changing the "Any CPU" option to "x86", I got rid of the exception.

Configuring NHibernate via Web.config in ASP.NET 4.0

So my unit tests are green, time to integrate this shiny new NHibernate-driven DAL in to my web app! I don't really want to maintain two configuration files so I've migrated hibernate.cfg.xml in to my Web.config file (i.e. I copypasta'd the contents of hibernate.cfg.xml in to my Web.config). Here is the relevant bits from my Web.config:
<configSections>
<section name="combres" type="Combres.ConfigSectionSetting, Combres, Version=2.0.0.0, Culture=neutral, PublicKeyToken=49212d24adfbe4b4"/>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=(local)\SQLExpress;Initial Catalog=MyProject;Integrated Security=True</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<listener class="MyProject.Sql.Listeners.SaveEventListener, MyProject" type="save"/>
<listener class="MyProject.Sql.Listeners.UpdateEventListener, MyProject" type="update"/>
</session-factory>
</nhibernate>
In Global.asax, on Application_Start, I try to initialize my configuration:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
SessionProvider.Initialize();
}
All this really does is call new Configuration().Configure().AddAssembly("MyProject"); in accordance with the configuration code above.
Interesting result: When I first hit the page, an exception is thrown:
[FileNotFoundException: Could not find file 'D:\Build\MyProject\Source\MyProject.Web\bin\hibernate.cfg.xml'.]
Well, I put the configuration in Web.config, shouldn't it be lookign there? Do I need to indicate "hey, NHibernate, pay attention -- the config data is in Web.config, dummy!" anywhere?
When I then hit F5, the page comes up. Hurray! Now I try to do something with data access and I get this exception:
[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>]
Huh, that's kinda weird too -- this worked just fine in test with configuration in hibernate.cfg.xml...and I am specifying this property in my Web.config...I wonder what could possibly be up?
So, anyone have any ideas? Any help in solving this mystery would be super!
*Update: I found the issue. It looks like I wasn't using the correct type in my configs section! D'oh. I have a complete write up on my blog.
Try calling the .Configure() method at the end:
new Configuration().AddAssembly("MyProject").Configure();
Or if you prefer put it into the web.config:
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="">
...
<mapping assembly="MyProject" />
</session-factory>
</nhibernate>
and then:
new Configuration().Configure();
Also make sure that the NHibernate.ByteCode.Castle.dll assembly is referenced in your web project.
It turns out that I was using the wrong type in the configuration section. You need to use NHibernate's section handler, not the generic .NET one. The behavior I was seeing was because it was all loaded in a singleton. On first visit, the configuration would fail. On subsequent visits it would just throw weird errors because the configuration failed originally!
There is one other caveat -- I have a complete writeup on my blog.

An exception occurred during configuration of persistence layer

I'm doing a project in Nhibernate with MySql in asp.net. In that while executing the code I got the error like
An exception occurred during configuration of persistence layer
in the below line
ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure).BuildSessionFactory();
So let me help to trouble shoot the error.
Here s my Configuration file
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<!-- an ISessionFactory instance -->
<session-factory>
<!-- properties -->
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.MySqlDataDriver
</property>
<property name="connection.connection_string">
Server=localhost;Database=hrms;User ID=test;Password=test;
</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<property name="show_mysql">true</property>
<!-- mapping files -->
<mapping resource="WebApp1.Job.hbm.xml" assembly="WebApp1" />
</session-factory>
</hibernate-configuration>
Incomplete configuration perhaps? Try manual configuration initialization like the following:
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");
cfg.SetProperty("connection.driver_class", "NHibernate.Driver.MySqlDataDriver");
cfg.SetProperty("connection.connection_string", "Server=YourServer;Database=YourDatabase;User ID=YourId;Password=YourPass;CharSet=utf8");
cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
cfg.AddAssembly("Your.Assembly.Name");
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
If everything works, move it to XML if you like.
Please read the inner exception that is being thrown and it's very likely you would know the cause. In my experience it can be as simple as the code is looking for the hibernate.cfg.xml file in bin/debug and could not find it.
I had a similar problem. Problem was that I used in Web.config:
<section name="nhibernate" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<nhibernate xmlns="urn:nhibernate-configuration-2.2">
.
.
.
</nhibernate>
instead of:
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
.
.
.
</hibernate-configuration>

Categories

Resources