I had something similar where I wanted to reject (throw away changes that I
have made to entities without it being flushed/commited to the db).
In the end I had to do 3 things.
1. in persistence.xml I prevented hibernate from flushing:
| <property name="hibernate.transaction.flush_before_completion"
value="false"/>
2.1. I annotated my the SFSB to prevent transactional behavior on method
boundaries:
| @Stateful
| @Name("contentManagementBean")
| @Conversational(ifNotBegunOutcome = "ViewContentHomePage")
| @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
| public class ContentManagementBean implements Serializable,
ContentManagement {
|
2.2 The method where I had to make the choice (to accept and persist or reject
and throw away everything) I annotated so that it requires a new transaction
(note that no flushing would occur in any other method that is not annotated
with this in this bean)
| @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
| public String save() throws Exception {
|
3. When deciding that I want to reject and prevent flushing I also had to evict
that specific object from the hibenate entity manager (this was the key for me
) and reload from the db (otherwise it might be flushed at a later stage)
| HibernateEntityManager hem = (HibernateEntityManager)em;
|
hem.getSession().evict(metaContentInfo);
| metaContentInfo = null;
| MetaContentInfo mciOrig =
em.find(
|
MetaContentInfo.class, mcid);
|
Or something along this line.
Regards
Louis
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3952048#3952048
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3952048
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user