So finally, I found a solution for my problem:
I have a bean that has not only methods writing to the database, but also provide some
other stuff. And I don't want to have auto-flushes after the latter.
You should prevent EJB from auto-flushing and write to the database explicitely when you
need it by em.flush().
There are several ways to switch auto-flushing off:
* @Begin(flushMode=FlushModeType.MANUAL)
|
| But this is still a feature from the future (i.e. only in the CVS version) and should
not be applied in production environments.
|
|
| * Try to set the flush mode on the Hibernate Session and manually perform transactions
... and tell me how you succeeded (i.e. this could work but you better don't waste
your time with this unless you're a real expert ;)).
|
|
| * @TransactionManagement(TransactionManagementType.BEAN)
|
| Usually Beans have Container Managed Transactions. But with this annotation you tell
EJB3 that you want to care about transactions yourself (User Managed Transactions). Well,
and this is what you also have to do then, of course. Back to stoneage - don't do this
;).
|
|
| * @TransactionAttribute
|
| As a default all methods have the transaction attribute REQUIRED. That means they are
all wrapped by a transaction. If you want to change this you can use the transaction
attribute NOT_SUPPORTED (btw: there are even more types, for the sake of completeness).
There are two possibilities:
|
| - To prevent a single method from being run in a transaction (which will lead to
auto-flushes) annotate it with
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED). If you have multiple
methods like this you need multiple annotations ;).
|
| - Or annotate the class itself with
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) (all methods will
"inherit" this). Then restore the default behaviour to some special methods
(e.g. store, delete) by annotating them with
@TransactionAttribute(TransactionAttributeType.REQUIRED)
|
| Depends on what is shorter for you. I annotated my class with NOT_SUPPORTED and the
store and delete method with REQUIRED. That's only three annotations... nice :).
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3965793#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...