use*_*037 5 hibernate seam3 ejb-3.0 jpa-2.0 jboss7.x
我有一个使用JBoss 7的Seam 3沙箱应用程序,Hibernate作为默认的JPA实现,以及作为Web前端的JSF.
我有问题,默认情况下吞下SQL UPDATE.
我在会话范围内的有状态EJB维护一个扩展范围的EntityManager和一个实体,容器管理事务(需要新的)
如果我通过以下方式扩展save():
a)entityManager.contains(entity)UPDATE按预期执行(结果为"true")
要么
b)entityManager.persist(entity)UPDATE按预期执行
问:据我所知,a)或b)都不需要规格,因为实体在整个过程中仍然受到管理.我不明白,为什么a)对储蓄有影响.我可以成像b)对保存有影响,但它不应该被要求,是吗?
欢迎任何解释.
这是我的EJB:
@Named
@ConversationScoped
@Stateful
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class LanguageBean {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager em;
@Inject
private UserTransaction transaction;
private Language value;
@Inject
Conversation conversation;
public LanguageBean() {
super();
}
@Begin
public void selectLanguage(Long anId) {
conversation.setTimeout(10 * 60 * 1000);
if (anId != null) {
value = em.find(Language.class, anId);
}
}
@BeforeCompletion
public void transactionComplete(){
System.out.println("transactionComplete");
}
public Language getValue() {
return value;
}
@Produces
@Named
@ConversationScoped
public Language getLanguage() {
return getValue();
}
public void setValue(Language aValue) {
value = aValue;
}
@End
public String save() {
// displays the changed attribute:
System.out.println("save code: "+value.getCode());
// why is either this required:
// boolean tempContains = em.contains(value);
// System.out.println("managed: "+tempContains);
// or: why is persist required:
em.persist(value);
return "languages?faces-redirect=true";
}
@End
public String cancel() throws SystemException {
transaction.setRollbackOnly();
return "languages?faces-redirect=true";
}
}
Run Code Online (Sandbox Code Playgroud)
尝试@Remove
在 注释的方法上添加注释@End
。
在我看来,@End
注释不会导致 bean 破坏。因此,即使在执行之后,持久上下文仍然处于活动状态save()
,并且其内容无法刷新到数据库。
归档时间: |
|
查看次数: |
1148 次 |
最近记录: |