hibernate插入错误(GenericADOException)

本文关键字:GenericADOException 错误 插入 hibernate | 更新日期: 2023-09-27 18:07:26

我是NHibernate的新手,所以我不确定我做错了什么。我目前收到这个消息:

无法插入:[NhibernateTest.Domain.Order # 5 ed0d146 - 644 b - 44 - ff - a080 f8cf3048158e] [SQL:INSERT INTO Order (OrderName, ShippingAddress, ShippingDate, OrderID)值(?, ?, ?, ?)]

我试图做一个基本的插入到我的数据库,它只有一个表。

我的域类:

    public class Order
{
    public virtual Guid OrderID { get; set; }
    public virtual string Name { get; set; }
    public virtual string ShipAddress { get; set; }
    public virtual string ShipDate { get; set; }
    public Order()
    {
    }
    public Order(string name, string shipAddress, string shipDate)
    {
        Name = name;
        ShipAddress = shipAddress;
        ShipDate = shipDate;
    }
}

我的映射:

<?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NhibernateTest" namespace="NhibernateTest.Domain">
    <class name="Order" table="Order" lazy="true">
        <id name="OrderID" column="OrderID">
            <generator class="guid" />
        </id>
        <property name="Name" column="OrderName" type="string" />
        <property name="ShipAddress" column="ShippingAddress" type="string" />
        <property name="ShipDate" column="ShippingDate" type="string" />
  </class>
</hibernate-mapping>
我OrderRepository

:

    public void Add(Order order)
    {
        /* Open up a session to the database. */
        using (ISession session = NHibernateHelper.OpenSession())
        {
            /* Open up a transaction to the database since an order object will be added. */
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(order);
                transaction.Commit();
            }
        }
    }

这是我的AddMethod和loadCfg-function:

        [HttpPost]
    public ActionResult AddOrder(FormCollection form)
    {
        LoadNHibernateCfg();
        OrderRepository repo = new OrderRepository();
        var order = new Order { Name = form[0], ShipAddress = form[1], ShipDate = form[2] };
        //order.Name = form[0];
        //order.ShipAddress = form[1];
        //order.ShipDate = form[2];
        repo.Add(order);
        return Index();
    }
    public static void LoadNHibernateCfg()
    {
        var cfg = new Configuration();
        cfg.Configure();
        cfg.AddAssembly(typeof (Order).Assembly);
        new SchemaExport(cfg).Execute(true, false, true);
    }

我知道order对象在传递给. add -函数时具有该信息。所以我想这一定和我的映射有关?

谢谢

hibernate插入错误(GenericADOException)

Order为保留关键字。例如,当查询内容时,您使用Order by。下面是所有保留词的列表:http://msdn.microsoft.com/en-us/library/aa238507%28v=sql.80%29.aspx

您可以通过更改表名和映射来解决这个问题。例如,您可以将表命名为Orders:

<class name="Order" table="Orders" lazy="true">

我得到了这样的错误:无法插入:[RegEmails.Model.][SQL: INSERT INTO reg_info (MESSAGE_HASH, IS_INTERNAL, PRODUCT, SERVER, VERSION, MODULE, bridge_license, BRIDGE_LICENCE_EXPIRY, back_office_license, BACK_OFFICE_LICENCE_EXPIRY, COMMENT, CREATE_DATE) VALUES (?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]

我有一些像

<id name="info_id" column="INFO_ID">
  <generator class="identity" />
</id>
<property name="MessageHash" column="MESSAGE_HASH" length="512" />
<property name="IsInternal" column="IS_INTERNAL" />
<property name="Product" column="PRODUCT" />
<property name="Server" column="SERVER" />
<property name="Version" column="VERSION" />
<property name="Module" column="MODULE" />
<property name="BridgeLicence" column="BRIDGE_LICENCE" />
<property name="BridgeLicenceExpiry" column="BRIDGE_LICENCE_EXPIRY" />
<property name="BackofficeLicence" column="BACK_OFFICE_LICENCE" />
<property name="BackofficeLicenceExpiry" column="BACK_OFFICE_LICENCE_EXPIRY" />
<property name="Comment" column="COMMENT" />
<property name="CreateDate" column="CREATE_DATE" />

InnerException:字段列表中未知列'MESSAGE_HASH'

我通过移除

<id name="info_id" column="INFO_ID">
  <generator class="identity" />
</id>
<property name="MessageHash"  length="512" />
<property name="IsInternal"  />
<property name="Product" />
<property name="Server"  />
<property name="Version" />
<property name="Module"  />
<property name="BridgeLicence"  />
<property name="BridgeLicenceExpiry" />
<property name="BackofficeLicence" />
<property name="BackofficeLicenceExpiry"  />
<property name="Comment" />
<property name="CreateDate"  />

相关文章:
  • 没有找到相关文章