EJB 3.0中的merge被称为更新,通过merge (person)方法可以把Entity Bean更新到数据库。那么该方法跟无状态Bean和有状态Bean有什么关系吗?它跟transaction-scoped persistence context和extended persistence context上下文有没有关系?
在有状态Bean,且为extended persistence context上下文中,好像并不需要使用merge方法。
在有状态Bean,且为extended persistence context上下文中,好像并不需要使用merge方法。
解决方案 »
- 大家帮帮忙哦,程序报这个错是什么原因哦Exception in thread "main" java.lang.NoClassDefFoundError
- 旅馆预留房间网络服务系统
- 求教一个ajax高级问题
- 一个return语句问题
- About liferay's question!!
- proxool配置问题
- 在tomcat 5.0下,下载小文件时,报java.lang.IllegalStateException: getOutputStream() has already been called for this response错,下载大文件时没有问题,js
- 请问怎么在查找结果中继续查找
- hibernate求助
- jdk1.5+myEclipse+jboss(自带的j2ee1.4api)写了一个简单的j2EE project,部署完成,运行时错误!
- 为什么我重打了dwr 的jar包再换回去就不能用了?
- 郁闷啊~SSH中,第一个添加功能可以,第二个查询功能spring配置文件不起作用
transaction-scoped persistence context是由容器创建EntityManager,随着调用session bean方法的结束 事务被提交,extended persistence context面向于stateful session bean的它可以跨越多个Transaction,它随着stateful session bean的销毁EntityManager才销毁!
如果我在一个无状态会话Bean中使用一个transaction-scoped persistence context的EntityManager,比方说,这个会话Bean有几个改变实体Bean的方法,person是个实体Bean实例
如:
private static Person person;
public void updateName(string name){
person.setName(name);
}
public void updateID(string ID){
person.setID(ID);
}
public void updateSex(string Sex){
person.setSex(Sex);
}
是不是都要在每个update方法中都要调用EntityManager.persist(person);
看是否在一个JVM上,如果是在同一个JVM上,容器返回的不是一个实体Bean的代理,如果不在一个JVM上,那么容器返回的是一个代理对象,每调用一次实体Bean的方法都是一个RMI的接口交互,所以客户端要减少对实体Bean方法的调用!!
你的session bean设计的不正确 太细了 应该是粗粒度设计 减少rmi交互
例如
public void update(String id, String name, String gender) {
Person person = entityManager.find(Person.class, id);
if(null != name && !"".equals(name.trim()) {
person.setName(name);
}
........
entityManager.merge(person);}
只有刚刚new一个新的实体Bean后要调用EntityManager.persist(person); 吧,以后更改了这个实体Bean是调用entityManager.merge(person);