I have a Seam 3 sandbox using JBoss 7, Hibernate as a standard JPA implementation, and as JSF as a web interface.
I have a problem that SQL UPDATE is swallowed by default.
My stateful conversation EJB supports extended EntityManager coverage and one Entity, managed by a transaction container (requires a new one)
- EntityManager gets an injection
- EJB uses EM to load Entity and stores it in a field
- JSF application accesses EJB and its entity, changes String field
- JSF Application Calls Save Method in EJB
- In save (), I check if the Entities field has been changed -> it has been changed correctly
- I do nothing else, the container completes the transaction after the save () is complete.
- Problem: SQL update for the database is not performed.
If I continue save ():
a) entityManager.contains (entity) UPDATE is executed as expected (the result is "true")
OR
b) entityManager.persist (entity) UPDATE is executed as expected
Q: As far as I understand, specifications are not needed for either a) or b), because Entity remains manageable throughout the process. I do not understand why a) affects savings. I can depict b) affects conservation, but is it not necessary if it is?
Any explanation is appreciated.
Here is my 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() {
System.out.println("save code: "+value.getCode());
em.persist(value);
return "languages?faces-redirect=true";
}
@End
public String cancel() throws SystemException {
transaction.setRollbackOnly();
return "languages?faces-redirect=true";
}
}
source
share