---
title: "hibernate错误 Unknown column 'resourcese0_.elt' in 'field list'"
author: "xcxn"
date: "2013-08-07T17:43:27Z"
tags: []
categories: ["编程语言"]
slug: "hibernate-unknown-column-resourcese0-elt-in-field-list"
draft: false
lastmod: "2013-08-07T17:43:26Z"
id: 1921658
url: "https://xcxn.iteye.com/blog/1921658"
---

错误如图：  
![](http://dl2.iteye.com/upload/attachment/0087/9488/2797a922-d807-3bbb-9745-71e0a66ff982.jpg)  
其中的 resourcese0\_为一个实体对象，但是由于在做关联查询时没有在映射文件中配置column属性导致以上错误，究其原因为在做通过中间表进行关联查询时如果不在many-to-many中配置column属性，hibernate在查询时会自动为resourcese0\_添加一个elt属性，但是这个实体类，映射文件，数据库中都不含有elt属性，所以数据库会报错。

映射文件如下：

```
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-7-17 17:05:27 by Hibernate Tools 3.6.0 -->
<hibernate-mapping>
    <class name="com.tarena.bookshop.security.model.DAuthorities" table="d_authorities" catalog="dangdang">
        <id name="authorityId" type="java.lang.Integer">
            <column name="authority_id" />
            <generator class="identity" />
        </id>
        <property name="authorityName" type="string">
            <column name="authority_name" length="40" not-null="true" />
        </property>
        <property name="authorityDesc" type="string">
            <column name="authority_desc" length="100" />
        </property>
        <property name="enabled" type="int">
            <column name="enabled" not-null="true" />
        </property>
        <property name="issys" type="int">
            <column name="issys" not-null="true" />
        </property>
        <set name="resourceses" table="d_authorities_resources" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="authority_id" not-null="true" />
            </key>
            <!-- 此处之前没有写column="resource_id"  导致 hibernate自动为DResources添加了一个elt属性导致数据库报错 -->
            <many-to-many column="resource_id" class="com.tarena.bookshop.security.model.DResources" />
        </set>
       
    </class>
</hibernate-mapping>
```