繁体   English   中英

Hibernate + Spring框架项目映射错误(异常)

[英]Hibernate+Spring framework project mapping error(exception)

造成原因:

org.hibernate.MappingException:无法确定类型:controller.Role,用于列:[org.hibernate.mapping.Column(ROLE)]

你能帮我吗?

这是我的地图课程

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="controler.Role" table="ROLE">
      <id name="roleId" column="ROLEID">
          <generator class="increment"/>
      </id>
      <property name="title" column="TITLE"/>
  </class>
</hibernate-mapping>

Role是一个pojo类,我在JavaDB中有一个名为Role的相关表。 角色表具有属性roleid(char)和roletitle(varchar)

原因:org.hibernate.MappingException:无法确定类型:controller.Role,用于列:[org.hibernate.mapping.Column(ROLE)]

我最初的假设是错误的。 但是,既然您提到了JavaDB,我怀疑ROLE实际上是一个保留关键字 尝试将表名称包含在映射文档的反引号中:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="controler.Role" table="`ROLE`">
      <id name="roleId" column="ROLEID">
          <generator class="increment"/>
      </id>
      <property name="title" column="TITLE"/>
  </class>
</hibernate-mapping>

参考

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="controler.Role" table=" ROLE "> <id name="roleId" type="int" column="ROLEID"> <generator class="increment"/> </id> <property name="title" column="TITLE"/> </class> </hibernate-mapping>

Java类的标准名称实际上是controler.Role吗? Role类的源代码是什么样的? 是否在名为controler的软件包中?

也许这个名字简直就是拼错了。

暂无
暂无

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

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