- 浏览: 567861 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
a1641693970:
还不错,学习了
BeanUtils使用总结(二)LazyDynaBean -
zjfshowtime:
很好的办法,学习了。
ORA-28001: the password has expired -
ya654277yo:
哦,多谢分享
Apache整合Tomcat后get方式提交中文乱码问题解决 -
foolkeeper:
nice !!
jvm内存参数设定 -
tracy821:
谢谢了,找了好久才找到
关于Spring 声明式事务处理时,throws exception不回滚的问题
一、POJO
public class Customer {
private Long id;
private String name;
private String address;
private String postcode;
private String sex;
private List<Orders> orderlist = new ArrayList<Orders>();
private Long id;
private String name;
private String address;
private String postcode;
private String sex;
private List<Orders> orderlist = new ArrayList<Orders>();
public String toString() {
return "Customer{" +
"id=" + id +
", name='" + name + '\'' +
", address='" + address + '\'' +
", postcode='" + postcode + '\'' +
", sex='" + sex + '\'' +
", orderlist=" + orderlist.size() +
'}';
}
return "Customer{" +
"id=" + id +
", name='" + name + '\'' +
", address='" + address + '\'' +
", postcode='" + postcode + '\'' +
", sex='" + sex + '\'' +
", orderlist=" + orderlist.size() +
'}';
}
public class Orders {
private Long id;
private String code;
private Long customerId;
private Customer customer;
private Long id;
private String code;
private Long customerId;
private Customer customer;
public String toString() {
return "Orders{" +
"id=" + id +
", code='" + code + '\'' +
", customerId=" + customerId +
'}';
}
return "Orders{" +
"id=" + id +
", code='" + code + '\'' +
", customerId=" + customerId +
'}';
}
二、SqlMap
Customer.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="customer">
<typeAlias alias="customer" type="com.lavasoft.ssi.domain.Customer"/>
<resultMap id="result_base" class="customer">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="address" column="address"/>
<result property="postcode" column="postcode"/>
<result property="sex" column="sex"/>
</resultMap>
<resultMap id="result" class="customer" extends="result_base">
<result property="orderlist" column="id" select="orders.findByCustomerId"/>
</resultMap>
<insert id="insert" parameterClass="customer">
insert into customer(address,postcode,sex,name) values(#address#,#postcode#,#sex#,#name#)
<selectKey keyProperty="id" resultClass="long">
select LAST_INSERT_ID()
</selectKey>
</insert>
<select id="getById" parameterClass="long" resultMap="result_base">
select * from customer where id = #value#
</select>
<select id="getWithCashById" parameterClass="long" resultMap="result">
select * from customer where id = #value#
</select>
<select id="getWithCashByIdInnerjoin" parameterClass="long" resultClass="customer" resultMap="result">
select c.* from customer c inner join orders o on c.id=o.customerId
</select>
</sqlMap>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="customer">
<typeAlias alias="customer" type="com.lavasoft.ssi.domain.Customer"/>
<resultMap id="result_base" class="customer">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="address" column="address"/>
<result property="postcode" column="postcode"/>
<result property="sex" column="sex"/>
</resultMap>
<resultMap id="result" class="customer" extends="result_base">
<result property="orderlist" column="id" select="orders.findByCustomerId"/>
</resultMap>
<insert id="insert" parameterClass="customer">
insert into customer(address,postcode,sex,name) values(#address#,#postcode#,#sex#,#name#)
<selectKey keyProperty="id" resultClass="long">
select LAST_INSERT_ID()
</selectKey>
</insert>
<select id="getById" parameterClass="long" resultMap="result_base">
select * from customer where id = #value#
</select>
<select id="getWithCashById" parameterClass="long" resultMap="result">
select * from customer where id = #value#
</select>
<select id="getWithCashByIdInnerjoin" parameterClass="long" resultClass="customer" resultMap="result">
select c.* from customer c inner join orders o on c.id=o.customerId
</select>
</sqlMap>
Orders.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="orders">
<typeAlias alias="orders" type="com.lavasoft.ssi.domain.Orders"/>
<resultMap id="result_base" class="orders">
<result property="id" column="id"/>
<result property="code" column="code"/>
<result property="customerId" column="customerId"/>
</resultMap>
<resultMap id="result" class="orders" extends="result_base">
<result property="customer" column="customerId" select="customer.getById"/>
</resultMap>
<insert id="insert" parameterClass="orders">
insert into orders(id,code,customerId) values(#id#,#code#,#customerId#)
<selectKey keyProperty="id" resultClass="long">
select LAST_INSERT_ID()
</selectKey>
</insert>
<select id="findByCustomerId" resultMap="result_base" parameterClass="long">
select * from orders where customerId = #value#
</select>
<select id="getById" parameterClass="long" resultMap="result_base">
select * from orders where id = #value#
</select>
<select id="getByIdWithCash" resultMap="result" resultClass="orders" parameterClass="long">
select * from orders where id = #value#
</select>
</sqlMap>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="orders">
<typeAlias alias="orders" type="com.lavasoft.ssi.domain.Orders"/>
<resultMap id="result_base" class="orders">
<result property="id" column="id"/>
<result property="code" column="code"/>
<result property="customerId" column="customerId"/>
</resultMap>
<resultMap id="result" class="orders" extends="result_base">
<result property="customer" column="customerId" select="customer.getById"/>
</resultMap>
<insert id="insert" parameterClass="orders">
insert into orders(id,code,customerId) values(#id#,#code#,#customerId#)
<selectKey keyProperty="id" resultClass="long">
select LAST_INSERT_ID()
</selectKey>
</insert>
<select id="findByCustomerId" resultMap="result_base" parameterClass="long">
select * from orders where customerId = #value#
</select>
<select id="getById" parameterClass="long" resultMap="result_base">
select * from orders where id = #value#
</select>
<select id="getByIdWithCash" resultMap="result" resultClass="orders" parameterClass="long">
select * from orders where id = #value#
</select>
</sqlMap>
发表评论
-
Spring 多数据源声明式事务控制(PlatformTransactionManager )
2014-04-11 18:31 4669首先是TransactionManager的配置: ... -
Spring 动态数据源(AbstractRoutingDataSource )
2014-04-11 18:25 1612Spring动态配置多数据源,即在大型应用中对数据进行横向 ... -
(转)Spring Security 3.0 多页面登录配置
2012-10-19 17:01 5366网上很多文章是关于Spri ... -
Spring 中集成 JOTM 配置 JTA 事务
2011-12-27 19:52 1557Spring 中集成 JOTM 配置 JTA 事务: ... -
Spring 3.1整合EhCache
2011-08-29 16:42 1435Spring 3.1提供了对cache的 ... -
spring集成xfire教程
2011-04-02 15:20 1549配置web.xml <!-- SPRING ... -
关于Spring 声明式事务处理时,throws exception不回滚的问题
2010-09-29 23:31 8963前一段时间,项目代码评审,发现有TX不使用Spri ... -
iBatis SqlMap 的配置总结 收藏
2010-07-22 14:30 3722核心提示:SqlMap的配 ... -
ibatis oscache 使用中miss cache
2010-06-10 13:17 2852原始配置信息: <cacheModel id=&quo ... -
ibatis oscache配置以及【文件名、目录名或卷标语法不正确】错误解决
2010-05-26 13:13 3371sqlmap-config.xml 配置如下: < ... -
Hibernate+ehcache二级缓存技术
2010-02-01 20:57 8811、首先设置EhCache,建立配置文件ehcache.XML ... -
Hibernate的缓存讨论
2010-02-01 20:50 1082一般系统中有三种情况 ... -
OpenSessionInView Filter 但是发现不生效(转载)
2010-01-25 15:35 1751今天有一个朋友问了我一个问题,他使用的是Hibernate/S ... -
spring有三种启动方式,使用ContextLoaderServlet,ContextLoader
2010-01-19 17:25 1131spring有三种启动方式,使用ContextLoaderSe ... -
ApplicationContext和BeanFactory的关于单实例bean装载的区别
2010-01-19 17:04 1193Bean工厂延迟载入所有的Bean,直到getBean()方法 ... -
Spring AOP 学习小结(转载)
2010-01-06 21:24 1406一、AOP 概念 Joinpoint ... -
AOP术语(转载)
2010-01-06 21:04 994AOP术语(转载) 2009-07-16 22:12 ... -
spring Lookup方法注入(转)---cglib解决子类过多问题、重构
2010-01-06 17:33 5888“Lookup方法”可以使Spri ... -
Spring JTA应用之Atomikos配置
2010-01-05 23:17 3701Atomikos,是一个基于Java的开源事务管理器,提供了事 ... -
多对多关系中Set的查询
2010-01-05 22:27 1055多对多关系中Set的查询 一个老师教多个学生,一个学生 ...
相关推荐
ibatisDemo 入门源码
ibatis demo,ibatis例子,ibatis示例
springmvc+ibatis demo搭建实现CRUD操作简单 有静态页面话技术
一个ibatis的demo含数据库哦,通过用户登录测试。
ibatis配置多表关联(一对一、一对多、多对多
快速入手ibatis,内含其增删改查例子,以及配套的讲解视频。
ibatis小例子Demo,对于初学者是个很好的例子。
最简单的IBatis for .net实现
ibatis 一对多关系映射 ibatis 一对多关系映射ibatis 一对多关系映射
ibatis 例子 ibatisDemo Demo ibatis 例子 ibatisDemo Demo
struts+spring+ibatis的Demo struts+spring+ibatis的Demo struts+spring+ibatis的Demo
IbatisDemo包含完整的Ibatis的文档,例子和必要的jar包,
iBatisDemo
NULL 博文链接:https://self4j.iteye.com/blog/906319
简单整合了struts1+ibatis+Spring demo
利用ibatis框架写的一个demo,真的很好
NULL 博文链接:https://keer2345.iteye.com/blog/673391
ch07_ibatisDemo.rar
Ibatis demo 从0基础到入门,内有学习总结,初学者可以下载看下,若有疑问可以留言
ibatisDemo 数据库半自动化实现方式,比hibernate 更灵活,电信,淘宝用的数据库操作,配置上较好的数据库连接池更好