[英]NHibernate Oracle mapping problem
Before stating the problem, please look at the code 在说明问题之前,请先看一下代码
Database(Oracle) SQL: 数据库(Oracle)SQL:
create table test_tab(
id number,
Name varchar2(50)
);
Corresponding Class in C#: C#中的相应类:
public class TestTable
{
private long id;
public virtual long Id {
get {
return id;
}
set {
id = value;
}
}
private string name;
public virtual string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
The mapping file for this: 映射文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataTransfer" namespace="DataTransfer">
<class name="DataTransfer.Models.TestTable, DataTransfer" table="TEST_TAB">
<id name="Id" column="ID" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">
seq_test
</param>
</generator>
</id>
<property name="Name" column="NAME" type="string" not-null="false"/>
</class>
</hibernate-mapping>
The "TestTable" class is inside the Models folder under DataTransfer project “ TestTable”类位于DataTransfer项目下的Models文件夹中
hibernate configuration figuration file: 休眠配置配置文件:
<?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="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Data Source=xe;Persist Security Info=True;User ID=hr;Password=hr;Unicode=True</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<!-- mapping files -->
<mapping assembly="DataTransfer" />
</session-factory>
</hibernate-configuration>
And here is my DataAccessLayer Code; 这是我的DataAccessLayer代码;
public void AddToTestTable(Test_Tab user)
{
using (ISession session = GetSession())
{
using (ITransaction tx = session.BeginTransaction())
{
try
{
session.Save(user);
session.Flush();
}
catch (NHibernate.HibernateException)
{
tx.Rollback();
throw;
}
}
}
}
Now the problem is when I insert any value to the database(using simple ASP.NET form) nothing happens(even no exceptions!). 现在的问题是,当我向数据库中插入任何值(使用简单的ASP.NET表单)时,什么也没有发生(甚至没有异常!)。 But it worked perfectly when i did not use "Models" folder for TestTable Class and "Mappings" folder for mapping files. 但是当我没有为TestTable Class使用“ Models”文件夹而没有为映射文件使用“ Mappings”文件夹时,它可以完美地工作。 Please help me out. 请帮帮我。
确保.hbm.xml
映射文件作为资源嵌入到程序集DataTransfer
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.