保存失败!~ 大家帮我看看啊

问题描述

<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">        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显示了值

解决方案

尝试把你的pojo写成这样,在Type 上我添加了一个方便的方法 addXuqiu。另外,你的cascade控制在one端,所以保存时候只要保存one端,one端所依赖的另一端就自动保存了。package org.vo;import java.io.Serializable;public class Xuqiu implements Serializable {private Integer id; private Integer typeid; private String name; private String xuqiu; private String fdate; private String gdate; private Integer state; private Type type; public Xuqiu() { }public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public Integer getTypeid() {return typeid;}public void setTypeid(Integer typeid) {this.typeid = typeid;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getXuqiu() {return xuqiu;}public void setXuqiu(String xuqiu) {this.xuqiu = xuqiu;}public String getFdate() {return fdate;}public void setFdate(String fdate) {this.fdate = fdate;}public String getGdate() {return gdate;}public void setGdate(String gdate) {this.gdate = gdate;}public Integer getState() {return state;}public void setState(Integer state) {this.state = state;}public Type getType() {return type;}public void setType(Type type) {this.type = type;} }package org.vo;import java.util.*;import java.io.Serializable;public class Type implements Serializable {private Integer typeid; private String typename; private Set xuqius = new HashSet(); public Type() { } public Integer getTypeid() {return typeid;}public void setTypeid(Integer typeid) {this.typeid = typeid;}public String getTypename() {return typename;}public void setTypename(String typename) {this.typename = typename;}public Set getXuqius() {return xuqius;}public void setXuqius(Set xuqius) {this.xuqius = xuqius;} public void addXuqiu(Xuqiu xq) { xq.setType(this); xuqius.add(xq); } }package org.vo;import java.util.List;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import persistence.HibernateUtil;public class Test {public static void main(String[] args) {SessionFactory sessionFactory = HibernateUtil.getSessionFactory();Session session = sessionFactory.openSession();Transaction tx = session.beginTransaction();Type type = new Type();type.setTypename("a");Xuqiu xq = new Xuqiu();xq.setFdate("a");xq.setGdate("a");xq.setName("a");xq.setState(1);xq.setXuqiu("a");type.addXuqiu(xq);session.save(type);tx.commit();session.close();HibernateUtil.shutdown();}}

时间: 2024-08-01 21:26:41

保存失败!~ 大家帮我看看啊的相关文章

:( 用多线程向Access中成批导入数据时,开始执行一段时间没问题,再后就保存失败了。

问题描述 用多线程向Access中成批导入数据时,开始执行一段时间没问题,再后就保存失败了.向Access中添加数据的语句没有错误,用SQL2K试过没有问题.得到在向获取Access添加数据时的错误为"未明确的错误".估计可能是添加数据时,Access成受不了了,所以才报错.但想想应该是有什么办法可以解决的.向Access添加数据的部分如下://保存数据到AccesspublicstringInfoSave(stringstrDBFile,string[]Info){try{strin

微信公众号多图文素材编辑完成保存失败该怎么解决?

本文以图文结合的形式告诉大家怎么解决公众号多图文素材编辑完成保存失败的问题 1.其实这个是大家对多图文的理解偏差造成的,所谓的多图文,不是"多图"文,而是"多"图文,也就是说并不是一个文章里有多张图就是多图文,而是至少两篇文章组成一组文章才能被称为多图文.每个文章里面有几张图并不是重点,重点是"多图文"至少是两篇文章组成一个文章组才能被成为"多"图文.所以如果大家想发一篇文章里有多个图片,那么应该选择单图文,只有在需要发布多篇

C# ASP.NET查找数据生成Excel时提示保存,但保存失败,重新下载后保存成功但是打开时提示文件已经损坏!Excel2010,请指教,谢谢!

问题描述 C#ASP.NET查找数据生成Excel时提示保存,但保存失败,重新下载后保存成功但是打开时提示文件已经损坏!Excel2010,请指教,谢谢!我的下载方法代码如下:publicvoidDownLoad(stringExcelName,stringFileName){try{if(!String.IsNullOrEmpty(ExcelName)||!String.IsNullOrEmpty(FileName)){Response.Charset="GB2312";Respon

有道云笔记显示保存失败怎么办?

  出现此问题一般是由于笔记内容有特殊格式导致笔记无法保存. 您可以把此篇笔记复制到新的笔记中(建议选择纯文本黏贴),删除此篇笔记再同步一下试试.

cookie的值保存失败-cookie保存不了,代码如下

问题描述 cookie保存不了,代码如下 if (Response.Cookies["User"].Value == null) { Label1.Text = (Session["User"] as Users).UserName + "欢迎你!"; HttpCookie h = new HttpCookie("User"); h.Values.Add("DateTime", DateTime.Now.T

一对一保存失败

问题描述 登陆用户信息:users.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">

蔬菜还在室温保存?澳柯玛帮您“新鲜”过冬

冬天快到了,大家都开始忙着为过冬做储物准备.冬天气候干燥,肌肤也缺乏水分.室外寒冷的气候甚至会让老人和孩子的抵抗力下降,因此应该多吃蔬菜,既能补水,还能补充维生素,提高抵抗力.但这个时节的蔬菜都要经过长途运输,今天餐桌上的蔬菜,可能已经是上个礼拜摘下来的"剩菜"了.如何让蔬菜进到我们的菜篮子里之后,还能尽量保持新鲜,显得尤为重要.大部分人都觉得冬季本就温度较低,买来的蔬菜直接放在屋里室温保存就行.但对于北方家庭来说,这样做只会让灼热的暖气将仅有的新鲜成分一点点烤干,就算是在南方,蔬菜里

Magento 数据保存失败什么原因

部分字段内容太多以致超出该字段在数据表中的限制 尝试修改该字段在数据表中的限制或者修改字段类型.以下是一些类型字段的长度限制: TEXT – 64K MEDIUMTEXT – 16M LONGTEXT – 4G   post 数据的大小超出服务器限制 尝试通过修改 .htaccess 或者服务器设置,增加 php 的 post_max_size 值.   post 数据的数量超出服务器限制 尝试通过修改 .htaccess 或者服务器设置,增加 php 的 max_input_vars 值.  

jquery validate 触发不了验证 因为我有多个按钮提交所以我写成 &amp;amp;lt;input type=&amp;amp;quot;button&amp;amp;quot; value=&amp;amp;quot;保存&amp;amp;quot; onclick=&amp;amp;quot;save();&amp;amp;quot;/&amp;amp;gt; type不是submit 求解决办法

问题描述 <%@pagecontentType="text/html;charset=UTF-8"%><%@tagliburi="/WEB-INF/c.tld"prefix="c"%><%@tagliburi="/WEB-INF/fmt.tld"prefix="fmt"%><%@taglibprefix="spring"uri="htt