Hibernate 删除副表记录但不删除主表记录解决方法
2011-06-02 13:00
357 查看
小弟用hibernate不到一年,有许多技术锤炼还不够,写的方法难免有问题,真诚的欢迎大侠们指正不妥之处,请随时联系本人,以免误导别人.
公司的OA.所用的SSH(Spring+Struts1.0+Hibernate)
数据库表
--销售机会
if (select object_id ('sell_chance')) is not null
drop table sell_chance
create table sell_chance (
sc_id int identity(1,1) primary key,--标识ID
sc_no varchar(12) not null,--编号11
sc_source varchar(200) null,---来源11
sc_client_id int not null,---机会客户(外键--client_info--client_id)
sc_odds int not null,---概率11
sc_summary varchar(300) not null,--概要11
sc_relation_man varchar(30) null,--联系人11
sc_tel varchar(13) null,--电话11
sc_desc text null,--描述11
sc_create_man int null,--创建者--employee---empid11
sc_create_date datetime not null,--创建日期 默认系统时间11
sc_dispatch_man int null,--指派到 外键 employee--empid
sc_dispatch_date datetime null,--指派时间
sc_state int null,--状态 data_dic 中 dd_id--sell_chance_state
sc_crad int null,--服务类型 data_dic 中client_contet_crad11
sc_area int null,--所在区域 data_dic 中client_area11
sc_result bit null,--0开发失败 ---1 开发成功
sc_remark varchar(1000) null,--- 备注
sc_other1 varchar(10) null,--预留字段
flageDelete INT default(0),--删除标识(1表示删除、0表示未删除)
flageForDelete INT default(0) --彻底删除标识(1表示删除、0表示未删除)
)
go
--客户开发
if (select object_id ('exploitation_plan')) is not null
drop table exploitation_plan
create table exploitation_plan (
exp_id int identity,
sc_id int null,--销售机会ID
plan_date datetime null,--计划日期
plan_content text null,--计划内容
plan_result text null,--执行结果
flageDelete INT not null,--删除标识(1表示删除、0表示未删除)
flageForDelete INT not null,--彻底删除标识(1表示删除、0表示未删除)
constraint PK_EXPLOITATION_PLAN primary key nonclustered (exp_id)
)
go
SellChance.hbm.xm配置文件:
<hibernate-mapping>
<class name="com.ww.crm.entity.SellChance" table="sell_chance" schema="dbo" catalog="crm11">
<id name="scId" type="java.lang.Integer">
<column name="sc_id" />
<generator class="identity"></generator>
</id>
<many-to-one name="clientInfo" class="com.ww.crm.entity.ClientInfo" fetch="select" lazy="false">
<column name="sc_client_id" not-null="true" />
</many-to-one>
<many-to-one name="employeeByScDispatchMan" class="com.ww.crm.entity.Employee" fetch="select" lazy="false">
<column name="sc_dispatch_man" />
</many-to-one>
<many-to-one name="employeeByScCreateMan" class="com.ww.crm.entity.Employee" fetch="select" lazy="false">
<column name="sc_create_man" />
</many-to-one>
<many-to-one name="dataDicByScCrad" class="com.ww.crm.entity.DataDic" fetch="select" lazy="false">
<column name="sc_crad" />
</many-to-one>
<many-to-one name="dataDicByScArea" class="com.ww.crm.entity.DataDic" fetch="select" lazy="false">
<column name="sc_area" />
</many-to-one>
<many-to-one name="dataDicByScState" class="com.ww.crm.entity.DataDic" fetch="select" lazy="false">
<column name="sc_state" />
</many-to-one>
<property name="scNo" type="java.lang.String">
<column name="sc_no" length="12" not-null="true" />
</property>
<property name="scSource" type="java.lang.String">
<column name="sc_source" length="200" />
</property>
<property name="scOdds" type="java.lang.Integer">
<column name="sc_odds" not-null="true" />
</property>
<property name="scSummary" type="java.lang.String">
<column name="sc_summary" length="300" not-null="true" />
</property>
<property name="scRelationMan" type="java.lang.String">
<column name="sc_relation_man" length="30" />
</property>
<property name="scTel" type="java.lang.String">
<column name="sc_tel" length="13" />
</property>
<property name="scDesc" type="java.lang.String">
<column name="sc_desc" />
</property>
<property name="scCreateDate" type="java.sql.Timestamp">
<column name="sc_create_date" length="23" not-null="true" />
</property>
<property name="scDispatchDate" type="java.sql.Timestamp">
<column name="sc_dispatch_date" length="23" />
</property>
<property name="scResult" type="java.lang.Boolean">
<column name="sc_result" />
</property>
<property name="scRemark" type="java.lang.String">
<column name="sc_remark" length="1000" />
</property>
<property name="scOther1" type="java.lang.String">
<column name="sc_other1" length="10" />
</property>
<property name="flageDelete" type="java.lang.Integer">
<column name="flageDelete" />
</property>
<property name="flageForDelete" type="java.lang.Integer">
<column name="flageForDelete" />
</property>
<set name="exploitationPlans" inverse="true" cascade="delete">
<key>
<column name="sc_id" />
</key>
<one-to-many class="com.ww.crm.entity.ExploitationPlan" />
</set>
</class>
</hibernate-mapping>
ExploitationPlan.hbm.xml配置文件:
<hibernate-mapping>
<class name="com.ww.crm.entity.ExploitationPlan" table="exploitation_plan" schema="dbo" catalog="crm11">
<id name="expId" type="java.lang.Integer">
<column name="exp_id" />
<generator class="identity"></generator>
</id>
<many-to-one name="sellChance" class="com.ww.crm.entity.SellChance" fetch="select" lazy="false">
<column name="sc_id" />
</many-to-one>
<property name="planDate" type="java.sql.Timestamp">
<column name="plan_date" length="23"/>
</property>
<property name="planContent" type="java.lang.String">
<column name="plan_content"/>
</property>
<property name="planResult" type="java.lang.String">
<column name="plan_result" />
</property>
<property name="flageDelete" type="java.lang.Integer">
<column name="flageDelete" not-null="true" />
</property>
<property name="flageForDelete" type="java.lang.Integer">
<column name="flageForDelete" not-null="true" />
</property>
</class>
</hibernate-mapping>
删除副表记录但不删除主表记录解决方法:
在一(SellChance.hbm.xml)中设置 cascade="delete";在多的一面不需要设置什么
公司的OA.所用的SSH(Spring+Struts1.0+Hibernate)
数据库表
--销售机会
if (select object_id ('sell_chance')) is not null
drop table sell_chance
create table sell_chance (
sc_id int identity(1,1) primary key,--标识ID
sc_no varchar(12) not null,--编号11
sc_source varchar(200) null,---来源11
sc_client_id int not null,---机会客户(外键--client_info--client_id)
sc_odds int not null,---概率11
sc_summary varchar(300) not null,--概要11
sc_relation_man varchar(30) null,--联系人11
sc_tel varchar(13) null,--电话11
sc_desc text null,--描述11
sc_create_man int null,--创建者--employee---empid11
sc_create_date datetime not null,--创建日期 默认系统时间11
sc_dispatch_man int null,--指派到 外键 employee--empid
sc_dispatch_date datetime null,--指派时间
sc_state int null,--状态 data_dic 中 dd_id--sell_chance_state
sc_crad int null,--服务类型 data_dic 中client_contet_crad11
sc_area int null,--所在区域 data_dic 中client_area11
sc_result bit null,--0开发失败 ---1 开发成功
sc_remark varchar(1000) null,--- 备注
sc_other1 varchar(10) null,--预留字段
flageDelete INT default(0),--删除标识(1表示删除、0表示未删除)
flageForDelete INT default(0) --彻底删除标识(1表示删除、0表示未删除)
)
go
--客户开发
if (select object_id ('exploitation_plan')) is not null
drop table exploitation_plan
create table exploitation_plan (
exp_id int identity,
sc_id int null,--销售机会ID
plan_date datetime null,--计划日期
plan_content text null,--计划内容
plan_result text null,--执行结果
flageDelete INT not null,--删除标识(1表示删除、0表示未删除)
flageForDelete INT not null,--彻底删除标识(1表示删除、0表示未删除)
constraint PK_EXPLOITATION_PLAN primary key nonclustered (exp_id)
)
go
SellChance.hbm.xm配置文件:
<hibernate-mapping>
<class name="com.ww.crm.entity.SellChance" table="sell_chance" schema="dbo" catalog="crm11">
<id name="scId" type="java.lang.Integer">
<column name="sc_id" />
<generator class="identity"></generator>
</id>
<many-to-one name="clientInfo" class="com.ww.crm.entity.ClientInfo" fetch="select" lazy="false">
<column name="sc_client_id" not-null="true" />
</many-to-one>
<many-to-one name="employeeByScDispatchMan" class="com.ww.crm.entity.Employee" fetch="select" lazy="false">
<column name="sc_dispatch_man" />
</many-to-one>
<many-to-one name="employeeByScCreateMan" class="com.ww.crm.entity.Employee" fetch="select" lazy="false">
<column name="sc_create_man" />
</many-to-one>
<many-to-one name="dataDicByScCrad" class="com.ww.crm.entity.DataDic" fetch="select" lazy="false">
<column name="sc_crad" />
</many-to-one>
<many-to-one name="dataDicByScArea" class="com.ww.crm.entity.DataDic" fetch="select" lazy="false">
<column name="sc_area" />
</many-to-one>
<many-to-one name="dataDicByScState" class="com.ww.crm.entity.DataDic" fetch="select" lazy="false">
<column name="sc_state" />
</many-to-one>
<property name="scNo" type="java.lang.String">
<column name="sc_no" length="12" not-null="true" />
</property>
<property name="scSource" type="java.lang.String">
<column name="sc_source" length="200" />
</property>
<property name="scOdds" type="java.lang.Integer">
<column name="sc_odds" not-null="true" />
</property>
<property name="scSummary" type="java.lang.String">
<column name="sc_summary" length="300" not-null="true" />
</property>
<property name="scRelationMan" type="java.lang.String">
<column name="sc_relation_man" length="30" />
</property>
<property name="scTel" type="java.lang.String">
<column name="sc_tel" length="13" />
</property>
<property name="scDesc" type="java.lang.String">
<column name="sc_desc" />
</property>
<property name="scCreateDate" type="java.sql.Timestamp">
<column name="sc_create_date" length="23" not-null="true" />
</property>
<property name="scDispatchDate" type="java.sql.Timestamp">
<column name="sc_dispatch_date" length="23" />
</property>
<property name="scResult" type="java.lang.Boolean">
<column name="sc_result" />
</property>
<property name="scRemark" type="java.lang.String">
<column name="sc_remark" length="1000" />
</property>
<property name="scOther1" type="java.lang.String">
<column name="sc_other1" length="10" />
</property>
<property name="flageDelete" type="java.lang.Integer">
<column name="flageDelete" />
</property>
<property name="flageForDelete" type="java.lang.Integer">
<column name="flageForDelete" />
</property>
<set name="exploitationPlans" inverse="true" cascade="delete">
<key>
<column name="sc_id" />
</key>
<one-to-many class="com.ww.crm.entity.ExploitationPlan" />
</set>
</class>
</hibernate-mapping>
ExploitationPlan.hbm.xml配置文件:
<hibernate-mapping>
<class name="com.ww.crm.entity.ExploitationPlan" table="exploitation_plan" schema="dbo" catalog="crm11">
<id name="expId" type="java.lang.Integer">
<column name="exp_id" />
<generator class="identity"></generator>
</id>
<many-to-one name="sellChance" class="com.ww.crm.entity.SellChance" fetch="select" lazy="false">
<column name="sc_id" />
</many-to-one>
<property name="planDate" type="java.sql.Timestamp">
<column name="plan_date" length="23"/>
</property>
<property name="planContent" type="java.lang.String">
<column name="plan_content"/>
</property>
<property name="planResult" type="java.lang.String">
<column name="plan_result" />
</property>
<property name="flageDelete" type="java.lang.Integer">
<column name="flageDelete" not-null="true" />
</property>
<property name="flageForDelete" type="java.lang.Integer">
<column name="flageForDelete" not-null="true" />
</property>
</class>
</hibernate-mapping>
删除副表记录但不删除主表记录解决方法:
在一(SellChance.hbm.xml)中设置 cascade="delete";在多的一面不需要设置什么
相关文章推荐
- Hibernate 删除主表记录并删除副表记录解决方法
- hibernate 多表联合查询,分页,重复记录导致的总记录数不对的解决方法。
- Hibernate配置发生的问题及解决方法记录
- git stash pop 冲突,git stash list 中的记录不会自动删除的解决方法
- 【转】Linux下Oracle sqlplus无法使用命令退格删除和历史记录的解决方法(使用rlwrap)
- 处理hibernate多重级联关系下的删除解决方法
- mysql delete删除记录数据库空间不减少问题解决方法
- Datalist删除一条记录的解决方法
- 删除记录时即不想级联删除,又不想回滚事务的最佳解决方法
- Hibernate中数据库无法插入中文记录的解决方法
- mysql delete删除记录数据库空间不减少问题解决方法
- Linux Oracle下sqlplus无法使用命令退格删除和历史记录的解决方法(使用rlwrap)
- 删除MySql表中的大量记录后,文件不变小的解决方法
- Oracle下sqlplus无法使用命令退格删除和历史记录的解决方法--使用rlwrap
- spring+hibernate删除单条记录的几种方法
- 在DataGrid中删除记录时提示的解决方法
- 解决 SQL Server 2005 在表中有 Identity 删除了一条记录后,不能自动排序的方法
- Linux Oracle下sqlplus无法使用命令退格删除和历史记录的解决方法(使用rlwrap)
- [转] Linux Oracle下sqlplus无法使用命令退格删除和历史记录的解决方法(使用rlwrap)
- spring+hibernate删除单条记录的几种方法