错误如图:
其中的 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>