为什么我无法保存外键的值

zhangyupeng492 2008-10-09 09:55:59
<hibernate-mapping>
<class name="org.vo.Type" table="type">
<id name="typeid" type="java.lang.Integer">
<column name="typeid" />
<generator class="native" />
</id>
<property name="typename" type="java.lang.String">
<column name="typename" length="50" not-null="true" />
</property>
<set name="xuqius" inverse="true" cascade="all"
table="xuqiu" lazy="true" order-by="typeid">
<key>
<column name="typeid"/>
</key>
<one-to-many class="org.vo.Xuqiu" />
</set>
</class>
</hibernate-mapping>

private Integer typeid;
private String typename;
private Set xuqius;

<hibernate-mapping>
<class name="org.vo.Xuqiu" table="xuqiu">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<many-to-one name="type" class="org.vo.Type">
<column name="typeid"/>
</many-to-one>
<property name="name" type="java.lang.String">
<column name="name" length="50" not-null="true" />
</property>
<property name="xuqiu" type="java.lang.String">
<column name="xuqiu" length="2000" not-null="true" />
</property>
<property name="fdate" type="java.lang.String">
<column name="fdate" length="23" />
</property>
<property name="gdate" type="java.lang.String">
<column name="gdate" length="23" />
</property>
<property name="state" type="java.lang.Integer">
<column name="state" />
</property>
</class>
</hibernate-mapping>

private Integer id;
private Integer typeid;
private String name;
private String xuqiu;
private String fdate;
private String gdate;
private Integer state;

private Type type;

在action中

XuqiuForm xuqiuForm = (XuqiuForm) form;

Xuqiu xuqiu = new Xuqiu();
xuqiu.setName(xuqiuForm.getName());
System.out.println(xuqiuForm.getName());

Type t = new Type();
t.setTypeid(Integer.getInteger(xuqiuForm.getType()));
xuqiu.setType(t);
System.out.println(xuqiuForm.getType());

xuqiu.setTypeid(Integer.getInteger(xuqiuForm.getType()));
xuqiu.setXuqiu(xuqiuForm.getXuqiu());
System.out.println(xuqiuForm.getXuqiu());
xuqiu.setFdate(xuqiuForm.getFdate());
System.out.println(xuqiuForm.getFdate());
xuqiu.setGdate(xuqiuForm.getGdate());
System.out.println(xuqiuForm.getGdate());
xuqiu.setState(Integer.getInteger(xuqiuForm.getState()));
System.out.println(xuqiuForm.getState());

try {
this.ixuqiudao.Save(xuqiu);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}

typeid为null 但是我System.out显示了值
...全文
62 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧