- 浏览: 42937 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
gyl199006:
public int insert(NameREQ reo,T ...
Hibernate多表级联更新 -
dackylike:
...
用javaScript控制DIV的显示 -
sjc106112:
漂亮嘛。
想请教一下:电子商务的购物车数据库设计: ...
Hibernate多表映射关系 -
myhometel:
logic:itertae标签的使用
1.表映射关系
主表:NameREQ
<hibernate-mapping>
<class name="com.cw.hibernate.entity.NameREQ" table="NAMEREQ" schema="LLF">
<comment>名称信息表</comment>
<id name="pripid" type="java.lang.Long">
<column name="PRIPID"/>
<generator class="native"></generator>
</id>
<property name="entname" type="java.lang.String">
<column name="ENTNAME" length="100" not-null="true">
<comment>企业(机构)名称</comment>
</column>
</property>
<property name="namedistrict" type="java.lang.String">
<column name="NAMEDISTRICT" length="40" not-null="true">
<comment>名称区划</comment>
</column>
</property>
<property name="enttra" type="java.lang.String">
<column name="ENTTRA" length="40" not-null="true">
<comment>企业(机构)字号</comment>
</column>
</property>
<property name="nameind" type="java.lang.String">
<column name="NAMEIND" length="30" not-null="true">
<comment>名称行业</comment>
</column>
</property>
<property name="orgform" type="java.lang.String">
<column name="ORGFORM" length="20" not-null="true">
<comment>组织形式</comment>
</column>
</property>
<property name="tradpiny" type="java.lang.String">
<column name="TRADPINY" length="200" not-null="true">
<comment>字号拼音</comment>
</column>
</property>
<property name="grpshform" type="java.lang.String">
<column name="GRPSHFORM" length="30" not-null="true">
<comment>集团简称</comment>
</column>
</property>
<property name="saveperto" type="java.util.Date">
<column name="SAVEPERTO" length="10" not-null="true">
<comment>保留期至</comment>
</column>
</property>
<set name="submitmaterial" inverse="true" cascade="save-update">
<key>
<column name="PRIPID" length="24" not-null="true">
<comment>企业ID</comment>
</column>
</key>
<one-to-many class="com.cw.hibernate.entity.SubmitMaterial" />
</set>
<set name="trustorinfo" inverse="true" cascade="save-update">
<key>
<column name="PRIPID" length="24" not-null="true">
<comment>企业ID</comment>
</column>
</key>
<one-to-many class="com.cw.hibernate.entity.TrustorInfo" />
</set>
</class>
</hibernate-mapping>
从表:SubmitMaterial
<hibernate-mapping>
<class name="com.cw.hibernate.entity.SubmitMaterial" table="SUBMITMATERIAL" schema="LLF">
<comment>提交材料表</comment>
<id name="materialid" type="java.lang.Long">
<column name="MATERIALID" length="10" />
<generator class="native"></generator>
</id>
<property name="materialname" type="java.lang.String">
<column name="MATERIALNAME" length="10" not-null="true">
<comment>材料名称</comment>
</column>
</property>
<many-to-one name="namereq" class="com.cw.hibernate.entity.NameREQ">
<column name="PRIPID" not-null="true">
<comment>企业ID</comment>
</column>
</many-to-one>
</class>
</hibernate-mapping>
从表:TrustorInfo
<hibernate-mapping>
<class name="com.cw.hibernate.entity.TrustorInfo" table="TRUSTORINFO" schema="LLF">
<comment>被委托人信息表</comment>
<id name="trustorid" type="java.lang.Long">
<column name="TRUSTORID" />
<generator class="native"></generator>
</id>
<many-to-one name="namereq" class="com.cw.hibernate.entity.NameREQ">
<column name="PRIPID" not-null="true">
<comment>企业ID</comment>
</column>
</many-to-one>
<!-- fetch="select"-->
<property name="trustorname" type="java.lang.String">
<column name="TRUSTORNAME" length="20" not-null="true">
<comment>姓名</comment>
</column>
</property>
<property name="documentname" type="java.lang.String">
<column name="DOCUMENTNAME" length="20" not-null="true">
<comment>证件名称</comment>
</column>
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" length="100" not-null="true">
<comment>通讯地址</comment>
</column>
</property>
<property name="submittype" type="java.lang.String">
<column name="SUBMITTYPE" length="20" not-null="true">
<comment>提交方式</comment>
</column>
</property>
<property name="grntime" type="java.lang.String">
<column name="GRNTIME" length="50" not-null="true">
<comment>准予登记所需时间</comment>
</column>
</property>
<property name="trustortel" type="java.lang.String">
<column name="TRUSTORTEL" length="20" not-null="true">
<comment>委托人联系电话</comment>
</column>
</property>
<property name="postalcode" type="java.lang.String">
<column name="POSTALCODE" length="20" not-null="true">
<comment>邮政编码</comment>
</column>
</property>
<property name="qualifications" type="java.lang.String">
<column name="QUALIFICATIONS" length="20" not-null="true">
<comment>资格</comment>
</column>
</property>
<property name="trustorno" type="java.lang.String">
<column name="TRUSTORNO" length="30" not-null="true">
<comment>证件号码</comment>
</column>
</property>
</class>
</hibernate-mapping>
NameREQ实体
package com.cw.hibernate.entity;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* NameREQ generated by MyEclipse Persistence Tools
*/
public class NameREQ implements java.io.Serializable {
// Fields
private Long pripid;
private String entname;
private String namedistrict;
private String enttra;
private String nameind;
private String orgform;
private String tradpiny;
private String grpshform;
private Date saveperto;
private Set submitmaterial = new HashSet(0);
private Set trustorinfo = new HashSet(0);
// Constructors
/** default constructor */
public NameREQ() {
}
/** minimal constructor */
public NameREQ(String entname, String namedistrict, String enttra, String nameind, String orgform, String tradpiny, String grpshform, Date saveperto) {
this.entname = entname;
this.namedistrict = namedistrict;
this.enttra = enttra;
this.nameind = nameind;
this.orgform = orgform;
this.tradpiny = tradpiny;
this.grpshform = grpshform;
this.saveperto = saveperto;
}
/** full constructor */
public NameREQ(Long pripid, String entname, String namedistrict, String enttra, String nameind, String orgform, String tradpiny, String grpshform, Date saveperto, Set submitmaterial, Set trustorinfo) {
this.pripid = pripid;
this.entname = entname;
this.namedistrict = namedistrict;
this.enttra = enttra;
this.nameind = nameind;
this.orgform = orgform;
this.tradpiny = tradpiny;
this.grpshform = grpshform;
this.saveperto = saveperto;
this.submitmaterial = submitmaterial;
this.trustorinfo = trustorinfo;
}
// Property accessors
public Long getPripid() {
return this.pripid;
}
public void setPripid(Long pripid) {
this.pripid = pripid;
}
public String getEntname() {
return this.entname;
}
public void setEntname(String entname) {
this.entname = entname;
}
public String getNamedistrict() {
return this.namedistrict;
}
public void setNamedistrict(String namedistrict) {
this.namedistrict = namedistrict;
}
public String getEnttra() {
return this.enttra;
}
public void setEnttra(String enttra) {
this.enttra = enttra;
}
public String getNameind() {
return this.nameind;
}
public void setNameind(String nameind) {
this.nameind = nameind;
}
public String getOrgform() {
return this.orgform;
}
public void setOrgform(String orgform) {
this.orgform = orgform;
}
public String getTradpiny() {
return this.tradpiny;
}
public void setTradpiny(String tradpiny) {
this.tradpiny = tradpiny;
}
public String getGrpshform() {
return this.grpshform;
}
public void setGrpshform(String grpshform) {
this.grpshform = grpshform;
}
public Date getSaveperto() {
return this.saveperto;
}
public void setSaveperto(Date saveperto) {
this.saveperto = saveperto;
}
public Set getSubmitmaterial() {
return submitmaterial;
}
public void setSubmitmaterial(Set submitmaterial) {
if(submitmaterial==null)
{
submitmaterial = (Set)new SubmitMaterial();
}
this.submitmaterial = submitmaterial;
}
public Set getTrustorinfo() {
return trustorinfo;
}
public void setTrustorinfo(Set trustorinfo) {
if(trustorinfo==null)
{
trustorinfo = (Set)new TrustorInfo();
}
this.trustorinfo = trustorinfo;
}
}
TrustorInfo 实体:
package com.cw.hibernate.entity;
import java.util.ArrayList;
import java.util.List;
/**
* TrustorInfo generated by MyEclipse Persistence Tools
*/
public class TrustorInfo implements java.io.Serializable {
// Fields
private Long trustorid;
private NameREQ namereq;
private String trustorname;
private String documentname;
private String address;
private String submittype;
private String grntime;
private String trustortel;
private String postalcode;
private String qualifications;
private String trustorno;
// Constructors
/** default constructor */
public TrustorInfo() {
}
/** full constructor */
public TrustorInfo(NameREQ namereq, String trustorname, String documentname, String address, String submittype, String grntime, String trustortel, String postalcode, String qualifications, String trustorno) {
this.namereq = namereq;
this.trustorname = trustorname;
this.documentname = documentname;
this.address = address;
this.submittype = submittype;
this.grntime = grntime;
this.trustortel = trustortel;
this.postalcode = postalcode;
this.qualifications = qualifications;
this.trustorno = trustorno;
}
// Property accessors
public Long getTrustorid() {
return this.trustorid;
}
public void setTrustorid(Long trustorid) {
this.trustorid = trustorid;
}
public NameREQ getNamereq() {
return namereq;
}
public void setNamereq(NameREQ namereq) {
this.namereq = namereq;
}
public String getTrustorname() {
return this.trustorname;
}
public void setTrustorname(String trustorname) {
this.trustorname = trustorname;
}
public String getDocumentname() {
return this.documentname;
}
public void setDocumentname(String documentname) {
this.documentname = documentname;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSubmittype() {
return this.submittype;
}
public void setSubmittype(String submittype) {
this.submittype = submittype;
}
public String getGrntime() {
return this.grntime;
}
public void setGrntime(String grntime) {
this.grntime = grntime;
}
public String getTrustortel() {
return this.trustortel;
}
public void setTrustortel(String trustortel) {
this.trustortel = trustortel;
}
public String getPostalcode() {
return this.postalcode;
}
public void setPostalcode(String postalcode) {
this.postalcode = postalcode;
}
public String getQualifications() {
return this.qualifications;
}
public void setQualifications(String qualifications) {
this.qualifications = qualifications;
}
public String getTrustorno() {
return this.trustorno;
}
public void setTrustorno(String trustorno) {
this.trustorno = trustorno;
}
}
SubmitMaterial实体:
package com.cw.hibernate.entity;
import java.util.HashSet;
import java.util.Set;
/**
* SubmitMaterial generated by MyEclipse Persistence Tools
*/
public class SubmitMaterial implements java.io.Serializable {
// Fields
private Long materialid;
private String materialname;
private NameREQ namereq;
// Constructors
/** default constructor */
public SubmitMaterial() {
}
/** minimal constructor */
public SubmitMaterial(String materialname,NameREQ namereq) {
this.materialname = materialname;
this.namereq = namereq;
}
// Property accessors
public Long getMaterialid() {
return this.materialid;
}
public void setMaterialid(Long materialid) {
this.materialid = materialid;
}
public String getMaterialname() {
return this.materialname;
}
public void setMaterialname(String materialname) {
this.materialname = materialname;
}
public NameREQ getNamereq() {
return namereq;
}
public void setNamereq(NameREQ namereq) {
this.namereq = namereq;
}
}
在NameREQDAO类中添加一个方法
public int insert(NameREQ reo,TrustorInfo info,SubmitMaterial sub)
{
Transaction tran = null;
Session session = HibernateUtil.getSession();
try{
tran = session.beginTransaction();
session.save(reo);
tran.commit();
session.close();
return 1;
}catch(Exception e)
{
e.printStackTrace();
return 0;
}
}
Action中调用
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
NameREQDAO ndao = new NameREQDAO();
String EntName = request.getParameter("EntName");
String NameDistrict = request.getParameter("NameDistrict");
String EntTra = request.getParameter("EntTra");
String NameInd = request.getParameter("NameInd");
String OrgForm = request.getParameter("OrgForm");
String TradPiny = request.getParameter("TradPiny");
String GrpShForm = request.getParameter("GrpShForm");
Date SavePerTo = Timestamp.valueOf(request.getParameter("SavePerTo"));
//企业信息实体
NameREQ req = new NameREQ(EntName,NameDistrict,EntTra,NameInd,OrgForm,TradPiny,GrpShForm,SavePerTo);
String TrustorName = request.getParameter("TrustorName");
String DocumentName = request.getParameter("DocumentName");
String TrustorNo = request.getParameter("TrustorNo");
String TrustorTel = request.getParameter("TrustorTel");
String Address = request.getParameter("Address");
String PostalCode = request.getParameter("PostalCode");
String SubmitType = request.getParameter("SubmitType");
String Qualifications = request.getParameter("Qualifications");
String GRNTime = request.getParameter("GRNTime");
//企业法人,委托人实体
TrustorInfo info = new TrustorInfo(req,TrustorName,DocumentName,Address,SubmitType,GRNTime,TrustorTel,PostalCode,Qualifications,TrustorNo);
req.getTrustorinfo().add(info);
//提交材料
String[] MaterialName = request.getParameterValues("MaterialName");
String strname="";
SubmitMaterial mater=null;
for(int i=0;i<MaterialName.length;i++)
{
strname = MaterialName[i];
mater = new SubmitMaterial(strname,req);
req.getSubmitmaterial().add(mater);
}
int count = ndao.insert(req, info, mater);
if(count >0)
{
System.out.println("成功添加: "+count);
}else
{
System.out.println("添加失败");
}
return null;
}
主表:NameREQ
<hibernate-mapping>
<class name="com.cw.hibernate.entity.NameREQ" table="NAMEREQ" schema="LLF">
<comment>名称信息表</comment>
<id name="pripid" type="java.lang.Long">
<column name="PRIPID"/>
<generator class="native"></generator>
</id>
<property name="entname" type="java.lang.String">
<column name="ENTNAME" length="100" not-null="true">
<comment>企业(机构)名称</comment>
</column>
</property>
<property name="namedistrict" type="java.lang.String">
<column name="NAMEDISTRICT" length="40" not-null="true">
<comment>名称区划</comment>
</column>
</property>
<property name="enttra" type="java.lang.String">
<column name="ENTTRA" length="40" not-null="true">
<comment>企业(机构)字号</comment>
</column>
</property>
<property name="nameind" type="java.lang.String">
<column name="NAMEIND" length="30" not-null="true">
<comment>名称行业</comment>
</column>
</property>
<property name="orgform" type="java.lang.String">
<column name="ORGFORM" length="20" not-null="true">
<comment>组织形式</comment>
</column>
</property>
<property name="tradpiny" type="java.lang.String">
<column name="TRADPINY" length="200" not-null="true">
<comment>字号拼音</comment>
</column>
</property>
<property name="grpshform" type="java.lang.String">
<column name="GRPSHFORM" length="30" not-null="true">
<comment>集团简称</comment>
</column>
</property>
<property name="saveperto" type="java.util.Date">
<column name="SAVEPERTO" length="10" not-null="true">
<comment>保留期至</comment>
</column>
</property>
<set name="submitmaterial" inverse="true" cascade="save-update">
<key>
<column name="PRIPID" length="24" not-null="true">
<comment>企业ID</comment>
</column>
</key>
<one-to-many class="com.cw.hibernate.entity.SubmitMaterial" />
</set>
<set name="trustorinfo" inverse="true" cascade="save-update">
<key>
<column name="PRIPID" length="24" not-null="true">
<comment>企业ID</comment>
</column>
</key>
<one-to-many class="com.cw.hibernate.entity.TrustorInfo" />
</set>
</class>
</hibernate-mapping>
从表:SubmitMaterial
<hibernate-mapping>
<class name="com.cw.hibernate.entity.SubmitMaterial" table="SUBMITMATERIAL" schema="LLF">
<comment>提交材料表</comment>
<id name="materialid" type="java.lang.Long">
<column name="MATERIALID" length="10" />
<generator class="native"></generator>
</id>
<property name="materialname" type="java.lang.String">
<column name="MATERIALNAME" length="10" not-null="true">
<comment>材料名称</comment>
</column>
</property>
<many-to-one name="namereq" class="com.cw.hibernate.entity.NameREQ">
<column name="PRIPID" not-null="true">
<comment>企业ID</comment>
</column>
</many-to-one>
</class>
</hibernate-mapping>
从表:TrustorInfo
<hibernate-mapping>
<class name="com.cw.hibernate.entity.TrustorInfo" table="TRUSTORINFO" schema="LLF">
<comment>被委托人信息表</comment>
<id name="trustorid" type="java.lang.Long">
<column name="TRUSTORID" />
<generator class="native"></generator>
</id>
<many-to-one name="namereq" class="com.cw.hibernate.entity.NameREQ">
<column name="PRIPID" not-null="true">
<comment>企业ID</comment>
</column>
</many-to-one>
<!-- fetch="select"-->
<property name="trustorname" type="java.lang.String">
<column name="TRUSTORNAME" length="20" not-null="true">
<comment>姓名</comment>
</column>
</property>
<property name="documentname" type="java.lang.String">
<column name="DOCUMENTNAME" length="20" not-null="true">
<comment>证件名称</comment>
</column>
</property>
<property name="address" type="java.lang.String">
<column name="ADDRESS" length="100" not-null="true">
<comment>通讯地址</comment>
</column>
</property>
<property name="submittype" type="java.lang.String">
<column name="SUBMITTYPE" length="20" not-null="true">
<comment>提交方式</comment>
</column>
</property>
<property name="grntime" type="java.lang.String">
<column name="GRNTIME" length="50" not-null="true">
<comment>准予登记所需时间</comment>
</column>
</property>
<property name="trustortel" type="java.lang.String">
<column name="TRUSTORTEL" length="20" not-null="true">
<comment>委托人联系电话</comment>
</column>
</property>
<property name="postalcode" type="java.lang.String">
<column name="POSTALCODE" length="20" not-null="true">
<comment>邮政编码</comment>
</column>
</property>
<property name="qualifications" type="java.lang.String">
<column name="QUALIFICATIONS" length="20" not-null="true">
<comment>资格</comment>
</column>
</property>
<property name="trustorno" type="java.lang.String">
<column name="TRUSTORNO" length="30" not-null="true">
<comment>证件号码</comment>
</column>
</property>
</class>
</hibernate-mapping>
NameREQ实体
package com.cw.hibernate.entity;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
/**
* NameREQ generated by MyEclipse Persistence Tools
*/
public class NameREQ implements java.io.Serializable {
// Fields
private Long pripid;
private String entname;
private String namedistrict;
private String enttra;
private String nameind;
private String orgform;
private String tradpiny;
private String grpshform;
private Date saveperto;
private Set submitmaterial = new HashSet(0);
private Set trustorinfo = new HashSet(0);
// Constructors
/** default constructor */
public NameREQ() {
}
/** minimal constructor */
public NameREQ(String entname, String namedistrict, String enttra, String nameind, String orgform, String tradpiny, String grpshform, Date saveperto) {
this.entname = entname;
this.namedistrict = namedistrict;
this.enttra = enttra;
this.nameind = nameind;
this.orgform = orgform;
this.tradpiny = tradpiny;
this.grpshform = grpshform;
this.saveperto = saveperto;
}
/** full constructor */
public NameREQ(Long pripid, String entname, String namedistrict, String enttra, String nameind, String orgform, String tradpiny, String grpshform, Date saveperto, Set submitmaterial, Set trustorinfo) {
this.pripid = pripid;
this.entname = entname;
this.namedistrict = namedistrict;
this.enttra = enttra;
this.nameind = nameind;
this.orgform = orgform;
this.tradpiny = tradpiny;
this.grpshform = grpshform;
this.saveperto = saveperto;
this.submitmaterial = submitmaterial;
this.trustorinfo = trustorinfo;
}
// Property accessors
public Long getPripid() {
return this.pripid;
}
public void setPripid(Long pripid) {
this.pripid = pripid;
}
public String getEntname() {
return this.entname;
}
public void setEntname(String entname) {
this.entname = entname;
}
public String getNamedistrict() {
return this.namedistrict;
}
public void setNamedistrict(String namedistrict) {
this.namedistrict = namedistrict;
}
public String getEnttra() {
return this.enttra;
}
public void setEnttra(String enttra) {
this.enttra = enttra;
}
public String getNameind() {
return this.nameind;
}
public void setNameind(String nameind) {
this.nameind = nameind;
}
public String getOrgform() {
return this.orgform;
}
public void setOrgform(String orgform) {
this.orgform = orgform;
}
public String getTradpiny() {
return this.tradpiny;
}
public void setTradpiny(String tradpiny) {
this.tradpiny = tradpiny;
}
public String getGrpshform() {
return this.grpshform;
}
public void setGrpshform(String grpshform) {
this.grpshform = grpshform;
}
public Date getSaveperto() {
return this.saveperto;
}
public void setSaveperto(Date saveperto) {
this.saveperto = saveperto;
}
public Set getSubmitmaterial() {
return submitmaterial;
}
public void setSubmitmaterial(Set submitmaterial) {
if(submitmaterial==null)
{
submitmaterial = (Set)new SubmitMaterial();
}
this.submitmaterial = submitmaterial;
}
public Set getTrustorinfo() {
return trustorinfo;
}
public void setTrustorinfo(Set trustorinfo) {
if(trustorinfo==null)
{
trustorinfo = (Set)new TrustorInfo();
}
this.trustorinfo = trustorinfo;
}
}
TrustorInfo 实体:
package com.cw.hibernate.entity;
import java.util.ArrayList;
import java.util.List;
/**
* TrustorInfo generated by MyEclipse Persistence Tools
*/
public class TrustorInfo implements java.io.Serializable {
// Fields
private Long trustorid;
private NameREQ namereq;
private String trustorname;
private String documentname;
private String address;
private String submittype;
private String grntime;
private String trustortel;
private String postalcode;
private String qualifications;
private String trustorno;
// Constructors
/** default constructor */
public TrustorInfo() {
}
/** full constructor */
public TrustorInfo(NameREQ namereq, String trustorname, String documentname, String address, String submittype, String grntime, String trustortel, String postalcode, String qualifications, String trustorno) {
this.namereq = namereq;
this.trustorname = trustorname;
this.documentname = documentname;
this.address = address;
this.submittype = submittype;
this.grntime = grntime;
this.trustortel = trustortel;
this.postalcode = postalcode;
this.qualifications = qualifications;
this.trustorno = trustorno;
}
// Property accessors
public Long getTrustorid() {
return this.trustorid;
}
public void setTrustorid(Long trustorid) {
this.trustorid = trustorid;
}
public NameREQ getNamereq() {
return namereq;
}
public void setNamereq(NameREQ namereq) {
this.namereq = namereq;
}
public String getTrustorname() {
return this.trustorname;
}
public void setTrustorname(String trustorname) {
this.trustorname = trustorname;
}
public String getDocumentname() {
return this.documentname;
}
public void setDocumentname(String documentname) {
this.documentname = documentname;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getSubmittype() {
return this.submittype;
}
public void setSubmittype(String submittype) {
this.submittype = submittype;
}
public String getGrntime() {
return this.grntime;
}
public void setGrntime(String grntime) {
this.grntime = grntime;
}
public String getTrustortel() {
return this.trustortel;
}
public void setTrustortel(String trustortel) {
this.trustortel = trustortel;
}
public String getPostalcode() {
return this.postalcode;
}
public void setPostalcode(String postalcode) {
this.postalcode = postalcode;
}
public String getQualifications() {
return this.qualifications;
}
public void setQualifications(String qualifications) {
this.qualifications = qualifications;
}
public String getTrustorno() {
return this.trustorno;
}
public void setTrustorno(String trustorno) {
this.trustorno = trustorno;
}
}
SubmitMaterial实体:
package com.cw.hibernate.entity;
import java.util.HashSet;
import java.util.Set;
/**
* SubmitMaterial generated by MyEclipse Persistence Tools
*/
public class SubmitMaterial implements java.io.Serializable {
// Fields
private Long materialid;
private String materialname;
private NameREQ namereq;
// Constructors
/** default constructor */
public SubmitMaterial() {
}
/** minimal constructor */
public SubmitMaterial(String materialname,NameREQ namereq) {
this.materialname = materialname;
this.namereq = namereq;
}
// Property accessors
public Long getMaterialid() {
return this.materialid;
}
public void setMaterialid(Long materialid) {
this.materialid = materialid;
}
public String getMaterialname() {
return this.materialname;
}
public void setMaterialname(String materialname) {
this.materialname = materialname;
}
public NameREQ getNamereq() {
return namereq;
}
public void setNamereq(NameREQ namereq) {
this.namereq = namereq;
}
}
在NameREQDAO类中添加一个方法
public int insert(NameREQ reo,TrustorInfo info,SubmitMaterial sub)
{
Transaction tran = null;
Session session = HibernateUtil.getSession();
try{
tran = session.beginTransaction();
session.save(reo);
tran.commit();
session.close();
return 1;
}catch(Exception e)
{
e.printStackTrace();
return 0;
}
}
Action中调用
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
NameREQDAO ndao = new NameREQDAO();
String EntName = request.getParameter("EntName");
String NameDistrict = request.getParameter("NameDistrict");
String EntTra = request.getParameter("EntTra");
String NameInd = request.getParameter("NameInd");
String OrgForm = request.getParameter("OrgForm");
String TradPiny = request.getParameter("TradPiny");
String GrpShForm = request.getParameter("GrpShForm");
Date SavePerTo = Timestamp.valueOf(request.getParameter("SavePerTo"));
//企业信息实体
NameREQ req = new NameREQ(EntName,NameDistrict,EntTra,NameInd,OrgForm,TradPiny,GrpShForm,SavePerTo);
String TrustorName = request.getParameter("TrustorName");
String DocumentName = request.getParameter("DocumentName");
String TrustorNo = request.getParameter("TrustorNo");
String TrustorTel = request.getParameter("TrustorTel");
String Address = request.getParameter("Address");
String PostalCode = request.getParameter("PostalCode");
String SubmitType = request.getParameter("SubmitType");
String Qualifications = request.getParameter("Qualifications");
String GRNTime = request.getParameter("GRNTime");
//企业法人,委托人实体
TrustorInfo info = new TrustorInfo(req,TrustorName,DocumentName,Address,SubmitType,GRNTime,TrustorTel,PostalCode,Qualifications,TrustorNo);
req.getTrustorinfo().add(info);
//提交材料
String[] MaterialName = request.getParameterValues("MaterialName");
String strname="";
SubmitMaterial mater=null;
for(int i=0;i<MaterialName.length;i++)
{
strname = MaterialName[i];
mater = new SubmitMaterial(strname,req);
req.getSubmitmaterial().add(mater);
}
int count = ndao.insert(req, info, mater);
if(count >0)
{
System.out.println("成功添加: "+count);
}else
{
System.out.println("添加失败");
}
return null;
}
评论
1 楼
gyl199006
2012-10-21
public int insert(NameREQ reo,TrustorInfo info,SubmitMaterial sub)
这个方法中的后两个参数是不是多余了呢?
这个方法中的后两个参数是不是多余了呢?
发表评论
-
struts2_hibernate3_spring2配置文件简化
2010-01-28 16:58 8821. 以前使用的 applicationContext.xml ... -
Hibernate3应用的DetachedCriteria分页查询
2008-10-27 14:18 1957分页类: package com.iteye.common.u ... -
多个值的离线查询
2008-10-14 11:34 823/** * 名称查重 * @param qrybo 查重条 ... -
hibernate3中离线查询1
2008-10-08 16:54 2325Criteria 在查询方法设计上可以灵活的根据 Criter ... -
hibernate3中的离线查询2
2008-10-08 16:37 1320DetachedCriteria detachedCriter ... -
hibernate3中的离线查询1
2008-10-08 16:35 966假设要通过stuName查询一个学生Student记录,可以如 ... -
手动添加Hibernate3.2所需的库文件
2008-09-19 16:44 2358hibernate 3.2库文件(jar)依赖 • Fro ... -
Hibernate多表映射关系
2008-09-19 16:42 36261. 当两个表建立了一个中间关联表时,在配置文件中应该设置好中 ... -
Hibernate对DAO处理实例
2008-09-19 16:33 1126Hibernate 对Dao层的处理实例 有模糊查询和 ... -
Hibernate中的实体状态与Session(二)
2008-09-10 15:22 952(2)session.merge ()方法 该方法将修改表中 ... -
Hibernate中的实体状态与Session(一)
2008-09-10 15:16 872持久层的解决方案有许多,尤其以持久层框架的出现为持久层的开发带 ...
相关推荐
Hibernate的级联操作(增,删,该)
struts+hibernate+ajax级联菜单struts+hibernate+ajax级联菜单
Hibernate cascade (级联).docHibernate_cascade(级联).doc
Hibernate 一对多、多对一、级联、加载、反转
虽然Hibernate不怎么流行了不过有兴趣的可以看看
hibernate many-to-many级联保存,级联更新,级联删除
struts2 hibernate 实现无限级联 树形分类 基于struts2 hibernate 技术,实现对无限级联分类的crud操作
DWR+hibernate+spring级联下拉列表框 DWR+hibernate+spring级联下拉列表框
JavaProject实现hibernate3.2的级联关系,适合初学者熟悉各种级联关系。一对多,一朵一,多对多。
Hibernate级联操作一对多demo Hibernate级联操作一对多demo Hibernate级联操作一对多demo
第七章_Hibernate_-_级联策略 第七章
inverse Hibernate_级联关系说明_-_关于cascade和inverse的用法
Ajax+struts+hibernate实现级联菜单 Ajax+struts+hibernate实现级联菜单 Ajax+struts+hibernate实现级联菜单
hibernate3.2级联关系自身一对多双向关联,适合初学者熟悉hibernate框架。
hibernate 注解生成表 JPA注解1、@Entity(name="EntityName")必须,name为可选,对应数据库中一的个表2、@Table(name="",catalog="",schema="")可选,通常和@Entity配合使用,只能标注在实体的class定义处,表示实体...
Hibernate_范型_级联
包括t_card主表和t_person从表,实现基于session和hql的hibernate级联增删改查;
Hibernate级联操作.docx
HibernateHQL级联注意事项[归类].pdf