因为many-to-one,插入子对象错误

表article的sectorname 是表 sector(主键名也是sectorname)的外键
[color=red]Article.hbm.xml[/color]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >


name="Article"
table="ARTICLE"
>
false
name="Topic"
column="TOPIC"
type="string"
length="40"
>


<!-- name="Sectorname"
column="SECTORNAME"
type="string"
not-null="true"
length="40"
/> -->
name="sector"
column="sectorname
class="com.struts_learn.data.Sector"
/>


[color=red]代码:[/color]
Sector sector = new Sector();
sector.setSectorname("vu5");
sector.setCreateid("aaa");
sector.setCreatetime(new Date());
Article article = new Article();
article.setTopic("fadg5");
article.setSector(sector);
session.save(article);
tx.commit();

[color=red]log:[/color]Hibernate: insert into ARTICLE (SECTORNAME,TOPIC) values (?, ?)
报错:Caused by: java.sql.BatchUpdateException: ORA-01400: 无法将 NULL 插入 ("AB"."ARTICLE"."SECTORNAME")

             <!-- <property
        name="Sectorname"
        column="SECTORNAME"
        type="string"
        not-null="true"
        length="40"
    /> -->

把mapping文件注释去掉
[color=red]代码: [/color]

Sector sector = new Sector();
sector.setSectorname("vu5");
sector.setCreateid("aaa");
sector.setCreatetime(new Date());
Article article = new Article();
article.setTopic("fadg5");
article.setSector(sector);
article.setSectorname("vu5");
session.save(article);
tx.commit();

[color=red]log:Hibernate:[/color] insert into ARTICLE (SECTORNAME, sectorname, TOPIC) values (?, ?, ?)
报错:Caused by: java.sql.BatchUpdateException: ORA-00957: 列名重复

搞半天没明白,到底哪配错了...

设置cascade='all'或者'saveOrUpdate'或者你先save你的sector然后save多的那个