当前位置: 代码迷 >> Java Web开发 >> 一对多关系中,多的一方即是主键又是外键,myeclipse逆向工程生成hbm.xml文件有关问题
  详细解决方案

一对多关系中,多的一方即是主键又是外键,myeclipse逆向工程生成hbm.xml文件有关问题

热度:7879   发布时间:2016-04-10 22:42:13.0
一对多关系中,多的一方即是主键又是外键,myeclipse逆向工程生成hbm.xml文件问题
本帖最后由 u014490157 于 2014-04-01 17:09:26 编辑
多的一方plasmids hbm.xml配置文件
<?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">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.wsw.model.Plasmids" table="PLASMIDS" schema="PUBLIC" catalog="PUBLIC">
        <id name="entriesId" type="long">
            <column name="ENTRIES_ID" />
            <generator class="assigned" />
        </id>
        <many-to-one name="entries" class="com.wsw.model.Entries"  cascade="save-update" fetch="select">
           <column name="ENTRIES_ID" not-null="true" unique="true"/>
        </many-to-one>
        <property name="backbone" type="string">
            <column name="BACKBONE" length="127" />
        </property>
        <property name="circular" type="boolean">
            <column name="CIRCULAR" />
        </property>
        <property name="originOfReplication" type="string">
            <column name="ORIGIN_OF_REPLICATION" length="127" />
        </property>
        <property name="promoters" type="string">
            <column name="PROMOTERS" length="512" />
        </property>
        <property name="replicatesIn" type="string">
            <column name="REPLICATES_IN" />
        </property>
    </class>
</hibernate-mapping>

注意最上面的两个column name,两个一样:Repeated column in mapping for entity
执行insert,update的时候:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Repeated column in mapping for entity: com.wsw.model.Plasmids column: ENTRIES_ID (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:670)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:692)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:714)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:468)
at org.hibernate.mapping.RootClass.validate(RootClass.java:215)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1149)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)
at com.wsw.util.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at com.wsw.dao.EntriesDao.save(EntriesDao.java:13)
at com.wsw.service.EntriesServices.save(EntriesServices.java:11)
at com.wsw.servlet.getdata.GetDatasServlet.GetData(GetDatasServlet.java:29)
at com.wsw.util.csv.huan.huanList(huan.java:26)
at com.wsw.text.Text.main(Text.java:28)
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/wsw/model/Entries.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at com.wsw.util.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)
at com.wsw.util.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)
at com.wsw.dao.EntriesDao.save(EntriesDao.java:13)
at com.wsw.service.EntriesServices.save(EntriesServices.java:11)
  相关解决方案