第一章EJB 知识与运行环境配置....................................................................................................................................7
1.1 什么是ENTERPRICE JAVABEANS(EJB) .......................................................................................................................7
1.2 EJB 的运行环境.........................................................................................................................................................7
1.3 什么是JNDI ..............................................................................................................................................................7
1.4 下载与安装JDK........................................................................................................................................................8
1.5 下载与安装ECLIPSE..................................................................................................................................................9
1.6 下载与安装JBOSS......................................................................................................................................................9
1.7 运行第一个EJB3 例子...........................................................................................................................................11
1.8 熟悉JBOSS 的目录结构..........................................................................................................................................11
1.9 在JBOSS 部署应用..................................................................................................................................................12
1.10 如何恢复本书配套例子的开发环境.....................................................................................................................12
第二章会话BEAN(SESSION BEAN)...........................................................................................................................18
2.1 STATELESS SESSION BEANS(无状态BEAN)开发...................................................................................................19
2.1.1 开发只实现Remote 接口的无状态Session Bean............................................................................................19
2.1.2 开发只实现Local 接口的无状态Session Bean...............................................................................................32
2.1.3 开发实现了Remote 与Local 接口的无状态Session Bean.............................................................................34
2.2 实例池化(INSTANCE POOLING) ................................................................................................................................36
2.3 STATELESS SESSION BEAN 的生命周期.......................................................................................................................37
2.4 STATEFUL SESSION BEAN(有状态BEAN)开发......................................................................................................37
2.5 激活机制(ACTIVATION MECHANISM).......................................................................................................................39
2.6 STATEFUL SESSION BEAN 的生命周期.......................................................................................................................39
2.7 EJB 调用机制...........................................................................................................................................................39
2.8 如何改变SESSION BEAN 的JNDI 名称..................................................................................................................40
2.9 SESSION BEAN 的生命周期事件...............................................................................................................................42
2.10 拦截器(INTERCEPTOR) ...........................................................................................................................................45
2.11 依赖注入(DEPENDENCY INJECTION).......................................................................................................................51
2.11.1 资源类型的注入.............................................................................................................................................56
2.11.2 注入与继承关系.............................................................................................................................................59
2.11.3 自定义注入注释.............................................................................................................................................60
2.12 定时服务(TIMER SERVICE) ....................................................................................................................................60
2.13 安全服务(SECURITY SERVICE) ...............................................................................................................................62
2.13.1 自定义安全域.................................................................................................................................................75
第三章实体BEAN(ENTITY BEAN).............................................................................................................................77
3.1 JBOSS 数据源的配置................................................................................................................................................77
3.1.1 MySql 数据源的配置.........................................................................................................................................78
3.1.2 Ms Sql Server2000 数据源的配置.....................................................................................................................79
3.1.3 Oralce9i 数据源的配置.....................................................................................................................................79
3.2 单表映射的实体BEAN............................................................................................................................................80
3.3 成员属性映射..........................................................................................................................................................94
3.4 建议重载实体BEAN 的EQUALS()和HASHCODE()方法..........................................................................................99
3.5 映射的表名或列名与数据库保留字同名时的处理.............................................................................................100
3.6 多表映射的实体BEAN ..........................................................................................................................................100
EJB3.0 实例教程是《EJB3.0 入门经典》的精简版
版权所有:黎活明
3.7 持久化实体管理器ENTITYMANAGER ...................................................................................................................100
3.7.1 实体的状态.....................................................................................................................................................101
3.7.2 Entity 获取find()或getReference() ..................................................................................................................101
3.7.3 持久化实体persist() ......................................................................................................................................102
3.7.4 更新实体.........................................................................................................................................................102
3.7.5 合并Merge()...................................................................................................................................................103
3.7.6 删除Remove() ................................................................................................................................................104
3.7.7 执行JPQL 操作createQuery() .......................................................................................................................104
3.7.8 执行SQL 操作createNativeQuery()..............................................................................................................105
3.7.9 刷新实体refresh() ..........................................................................................................................................105
3.7.10 检测实体是否处于托管状态contains().......................................................................................................106
3.7.11 分离所有正在托管的实体clear() ................................................................................................................106
3.7.12 刷新flush()与设置flush 模式setFlushMode() ............................................................................................107
3.7.13 获取持久化实现者的引用getDelegate( )....................................................................................................107
3.8 关系/对象映射.......................................................................................................................................................107
3.8.1 双向一对多及多对一映射..............................................................................................................................107
3.8.2 单向一对多..................................................................................................................................................... 119
3.8.3 单向多对一..................................................................................................................................................... 119
3.8.4 双向一对一映射............................................................................................................................................. 119
3.8.5 单向一对一.....................................................................................................................................................129
3.8.6 双向多对多映射.............................................................................................................................................129
3.8.7 单向多对多.....................................................................................................................................................135
3.9 JPQL 查询...............................................................................................................................................................135
3.9.1 命名参数查询.................................................................................................................................................135
3.9.2 位置参数查询.................................................................................................................................................136
3.9.3 Date 参数.........................................................................................................................................................136
3.9.4 一个JPQL 查询例子.....................................................................................................................................137
3.9.5 命名查询.........................................................................................................................................................150
3.9.6 排序(order by).................................................................................................................................................151
3.9.7 查询部分属性.................................................................................................................................................151
3.9.8 查询中使用构造器(Constructor)...................................................................................................................152
3.9.9 聚合查询(Aggregation) ..................................................................................................................................153
3.9.10 关联(join)......................................................................................................................................................155
3.9.11 排除相同的记录DISTINCT.........................................................................................................................157
3.9.12 比较Entity ....................................................................................................................................................158
3.9.13 批量更新(Batch Update) ...............................................................................................................................158
3.9.14 批量删除(Batch Remove) ..............................................................................................................................159
3.9.15 逻辑非运算符NOT......................................................................................................................................159
3.9.16 使用操作符BETWEEN................................................................................................................................160
3.9.17 使用操作符IN..............................................................................................................................................160
3.9.18 使用操作符LIKE.........................................................................................................................................161
3.9.19 使用操作符IS NULL ...................................................................................................................................161
3.9.20 使用操作符IS EMPTY.................................................................................................................................162
3.9.21 字符串函数...................................................................................................................................................163
EJB3.0 实例教程是《EJB3.0 入门经典》的精简版
版权所有:黎活明
3.9.22 日期和时间函数...........................................................................................................................................163
3.9.23 数学函数.......................................................................................................................................................163
3.9.24 Member of ......................................................................................................................................................164
3.9.25 子查询...........................................................................................................................................................164
3.9.26 EXISTS ...........................................................................................................................................................164
3.9.27 All,ANY,SOME ...............................................................................................................................................165
3.9.28 结果集分页...................................................................................................................................................165
3.10 调用存储过程......................................................................................................................................................166
3.10.1 调用无返回值的存储过程............................................................................................................................166
3.10.2 调用返回单值的存储过程............................................................................................................................167
3.10.3 调用返回表全部列的存储过程....................................................................................................................168
3.10.4 调用返回部分列的存储过程........................................................................................................................169
3.11 复合主键(COMPOSITE PRIMARYKEY) ..................................................................................................................169
3.12 实体继承..............................................................................................................................................................170
3.12.1 每个类分层结构一张表(table per class hierarchy)......................................................................................170
3.12.2 每个子类一张表(table per subclass) ............................................................................................................170
3.12.3 每个具体类一张表(table per concrete class) ...............................................................................................171
3.13 ENTITY 的生命周期和状态..................................................................................................................................171
3.13.1 生命周期回调事件.......................................................................................................................................171
3.13.2 在外部类中实现回调...................................................................................................................................172
3.13.3 在Entity 类中实现回调...............................................................................................................................177
第四章事务管理服务.....................................................................................................................................................180
4.1 容器管理事务(CMT).............................................................................................................................................181
4.2 BEAN 管理事务(BMT) ...........................................................................................................................................182
4.3 事务并发的问题与处理........................................................................................................................................182
4.4 因并发事务引起的更新丢失问题及处理.............................................................................................................182
4.4.1 使用SERIALIZABLE 隔离级别避免更新丢失..............................................................................................183
4.4.2 修改代码逻辑来避免更新丢失......................................................................................................................183
4.4.3 使用悲观锁避免更新丢失..............................................................................................................................183
4.4.4 使用乐观锁避免更新丢失..............................................................................................................................184
第五章消息服务(JAVAMESSAGE SERVICE) .....................................................................................................184
5.1 消息驱动BEAN (MESSAGE DRIVEN BEAN) ............................................................................................................186
5.1.1 Queue 消息的发送与接收(PTP 消息传递模型)............................................................................................187
5.1.2 Topic 消息的发送与接收(Pub/sub 消息传递模型)........................................................................................194
5.1.3 消息选择器(Message selector).......................................................................................................................197
第六章WEB 服务(WEB SERVICE)............................................................................................................................197
6.1 EJB 容器模型的WEB SERVICE 开发......................................................................................................................198
6.2WEB 容器模型的WEB SERVICE 开发.....................................................................................................................198
6.3WEB SERVICE 的客户端调用..................................................................................................................................201
6.3.1 在J2SE 或Web 中调用Web Service ..............................................................................................................201
6.3.1 在EJB 中调用Web Service............................................................................................................................203
第七章在WEBLOGIC 中使用EJB3.0........................................................................................................................203
EJB3.0 实例教程是《EJB3.0 入门经典》的精简版
版权所有:黎活明
7.1WEBLOGIC 的安装..................................................................................................................................................203
7.2 启动WEBLOGIC EXAMPLES 服务器........................................................................................................................208
7.3 熟悉WEBLOGIC 的管理控制台..............................................................................................................................208
7.4 关闭WEBLOGIC EXAMPLES 服务器........................................................................................................................208
7.5 安装与删除企业应用............................................................................................................................................208
7.6 安装与删除EJB 模块...........................................................................................................................................208
7.7 安装与删除WEB 应用..........................................................................................................................................209
7.8 安装和引用JAVAEE 共享库..................................................................................................................................209
7.9 使用ANT 发布与卸载应用...................................................................................................................................209
7.10 创建JDBC 数据源.............................................................................................................................................209
7.11WEBLOGIC 的JNDI 名称......................................................................................................................................210
7.12 HELLOWORLD 例子..............................................................................................................................................210
7.13 ENTITY BEAN 应用例子........................................................................................................................................210
7.14MESSAGE-DRIVEN BEAN 应用例子.......................................................................................................................210
7.14.1 创建队列....................................................................................................................................................... 211
7.14.2 创建主题....................................................................................................................................................... 211
7.14.3 队列消息的发送与接收............................................................................................................................... 211
7.14.4 主题消息的发送与接收............................................................................................................................... 211
第八章STRUTS+EJB3.0 和JSF+EJB3.0 实战...........................................................................................................212
8.1 系统需求................................................................................................................................................................212
8.2 系统实现................................................................................................................................................................213
8.2.1 建立实体模型.................................................................................................................................................213
8.2.2 建立持久化配置文件.....................................................................................................................................214
8.2.3 建立会话Bean................................................................................................................................................214
8.2.4 Struts 客户端...................................................................................................................................................214
8.2.5 JSF 客户端......................................................................................................................................................215
8.2.6 创建EAR 部署描述文件...............................................................................................................................216
8.2.7 使用Ant 构建和部署程序..............................................................................................................................216
第九章项目实用知识.....................................................................................................................................................216
9.1 使用了第三方类库的企业应用.............................................................................................................................216
9.2 如何对EJB3 进行调试.........................................................................................................................................217
9.3 单元测试................................................................................................................................................................226
9.4 在独立的WEB 服务器或J2SE 中调用EJB.......................................................................................................231
9.4.1 Struts+Spring+EJB3.0.....................................................................................................................................232
9.1 如何获取最新的JBOSS 版本...............................................................................................................................233