简体   繁体   English

Hibernate忽略类和映射

[英]Hibernate ignores class & mapping

I seem to have this issue a lot. 我似乎经常遇到这个问题。

I setup a new class. 我设置了一个新课程。 I setup a new hbm.xml mapping and make it an embedded resource. 我设置了一个新的hbm.xml映射,并使其成为嵌入式资源。 I'll run my application and it will tell me I have a mismatch of attribute names ~ most commonly a case issue in the name of an attribute between the class and the mapping. 我将运行我的应用程序,它将告诉我属性名称不匹配〜最常见的情况是类与映射之间的属性名称出现问题。 Specific error "no getter / setter" for the name as shown in the mapping. 映射中显示的名称出现特定错误“ no getter / setter”。

But that is not the point of this quesiton, I fix that. 但这不是此问题的重点,我将其解决。

Now all typos are fixed but now hibernate doesn't do anything. 现在,所有错字都已修复,但是休眠状态什么也没做。 It just totally ignores the integration. 它只是完全忽略了集成。 It doesn't call SQL server, I know because I trace that on the SQL server side. 它不叫SQL Server,我知道是因为我在SQL Server端跟踪它。 I can even change the name of the view the mapping is pointed to and it is as if I don't even need a mapping ~ because hibernate is just ignoring it and everything in regard to this class. 我什至可以更改映射所指向的视图的名称,就好像我什至不需要映射〜一样,因为hibernate只是忽略了它以及与此类有关的所有内容。

If I turn on hibernate logging (log4net) to DEBUG level. 如果我将休眠日志记录(log4net)设置为DEBUG级别。 Other sql entities are shown in the logging but not my new one. 其他SQL实体显示在日志中,但未显示新实体。

How do you troubleshoot this? 您如何解决此问题?

In the past I've seen sometimes how something isn't perfectly jiving between the mapping and the SQL entity. 在过去,我有时会看到映射和SQL实体之间有些事情并没有完美地融合在一起。 And sometimes when I get those two ducks in a row things start to work. 有时当我连续得到那两只鸭子时,事情开始起作用。

Again, how do you troubleshoot this? 同样,您如何解决此问题? What is nHibernate doing to conparing the mapping to SQL and where it finds soemthing it doesn't like it just ignores it. nHibernate在将映射与SQL进行映射时会做些什么,发现它不喜欢它的地方只是忽略了它。

This is my class: 这是我的课:

public class Nodes {
    public virtual Int64 Id { get; set; }
    public virtual Int64 NodeId { get; set; }
    public virtual string Node { get; set; }
}

This is my map: 这是我的地图:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false" assembly="Prj" namespace="Prj.Nodes.Domain" default-lazy="false">
  <class name ="Nodes" table="dbo.vNodes" dynamic-update="false" lazy="false">
    <cache usage="read-only"/>
    <id name="Id" column="Id" type="Int64">
      <generator class="native" />
    </id>
    <property name="NodeId" />
    <property name="Node" />
  </class>
</hibernate-mapping>

This is my SQL: 这是我的SQL:

create table Nodes
(
    Id bigint identity(1,1) not null
    , NodeId bigint not null
    , Node varchar(10) null
)

insert into Nodes (NodeId, Node) values (100, 'Hello')
go

create view vNodes
as
    select 
        Id
        , NodeId
        , Node
    from Nodes with (NoLock)
go

And this is my application (method in a from a DOA): 这是我的应用程序(DOA中的一种方法):

using NHibernate;
public List<Nodes> LoadNodes()
{
    ICriteria c = NHibernateSessionManager.Instance.GetSession().CreateCriteria(typeof(Nodes));
    List<Nodes> n = c.List<Nodes>().ToList<Nodes>();
    return n;
}

Noting is logged about Nodes/vNodes in the hibernate logging file ~ not even at the DEBUG level. 休眠日志文件中记录了有关节点/ vNode的信息,甚至在DEBUG级别也没有。 Other methods and classes in the same DAO are logged. 记录同一DAO中的其他方法和类。 But nothing about this one. 但是关于这一点什么也没有。

I would rather have some error some where helping me to understand what I need to fix. 在某些可以帮助我了解需要解决的问题的地方,我宁愿有一些错误。

I use this pattern/architecture a lot and it works fantastically. 我经常使用这种模式/架构,并且效果很好。 But for on to many occasions when I start a new class/entity/integration and am first getting the ducks in a row. 但是在很多情况下,当我开始一个新的班级/实体/整合并开始连续学习这些鸭子时。

Respect & appreciation 尊重与赞赏

Just so happens today issue is the the mapping's file name was "Nodes.hdm..xml". 今天发生的问题恰恰是映射的文件名为“ Nodes.hdm..xml”。 no idea how the two dots got int there for the file extension. 不知道两个点是如何以int表示文件扩展名的。

Something I'd forgotten is how hibernate uses the file's name in the resources list of embedded resources in the executable. 我忘记的是,休眠是如何在可执行文件的嵌入式资源的资源列表中使用文件名的。 Any small thing wrong in the file names and hibernate won't know it has a resource it needs to use. 文件名和休眠中的任何小错误都不会知道它具有需要使用的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM