zoukankan      html  css  js  c++  java
  • 错误解决Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: pers.zhb.domain.Student column: classno (should be mapped with insert="false" update="false")

    1、在学习hibernate的一对多多对一关系的时候,出现了一下错误:

     2、错误原因:

    这是因为在配置student.hbm.xml的配置文件的时候出现了将两个属性映射到同一个字段:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping package="pers.zhb.domain">
        <class name="Student" table="student">
            <id name="studentno" column="studentno" >
                <generator class="native"></generator>
            </id>
            <property name="birthday" column="birthday"></property>
            <property name="classno" column="classno" ></property>
            <property name="email" column="email"></property>
            <property name="phone" column="phone"></property>
            <property name="sex" column="sex"></property>
            <property name="sname" column="sname"></property>
            <property name="point" column="point"></property>
            <many-to-one name="aClas" column="classno" class="Clas"></many-to-one>
        </class>
    </hibernate-mapping>

    3、解决方案:

     <property name="birthday" column="birthday"></property>
            <property name="classno" column="classno" insert="false" update="false"></property>
            <property name="email" column="email"></property>
            <property name="phone" column="phone"></property>
            <property name="sex" column="sex"></property>
            <property name="sname" column="sname"></property>
            <property name="point" column="point"></property>
            <many-to-one name="aClas" column="classno" class="Clas"></many-to-one>

    在属性的映射配置的地方加入insert="false" update="false"语句。

  • 相关阅读:
    sql2005创建存储过程
    sql 2005 调用存储过程
    sql2005创建存储过程(需要注意的几点)
    c# 日期处理
    Worldwind WMS Server安装
    Ubuntu11.10 设置默认Terminal为Terminator
    WordPress中文标题无法显示的解决方法
    Unknown Source的出现及解决
    Windows下 ant配置 以及 Unable to locate tools.jar
    安装WordPress中文包四步曲
  • 原文地址:https://www.cnblogs.com/zhai1997/p/11861103.html
Copyright © 2011-2022 走看看