• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[SCBCD] quick question on flush()

 
Laurent Lj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I wonder if an EntityManager.flush() causes always a TransactionRequiredException, while executed in no transactional context :

By example, in an extended persistence context that is supposed to queued all EntityManagers operations, what happened ?

Thanks by advance
Regards
 
Tamas Polgar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
you need a transaction to flush your changes you made during the transaction
so throwing a TransactionRequiredException makes a lot of sense.

if you use extended persistence context (with container managed transaction), it commits (flushes) after all business method (which uses transaction) invocation.
but it doesnt close (clear) the persistence context after the transaction. so you can use managed entities during the lifetime of the stateful session bean.

did I answer you question? or could you be more specific?
 
Tamas Polgar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry
you need a transaction to flush your changes you made during the transaction

is not properly right. It syncronizes the persistence context with the db.

so if you queue your modifications by using business methods without transaction, you can explicitly flush at the remove method (with transaction)
(but flush can happen anytime!)

check this out:
http://thatjavathing.blogspot.com/2009/04/extended-persistence-context.html
 
Laurent Lj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tamas Polgar wrote:Sorry
you need a transaction to flush your changes you made during the transaction

is not properly right. It syncronizes the persistence context with the db.

so if you queue your modifications by using business methods without transaction, you can explicitly flush at the remove method (with transaction)
(but flush can happen anytime!)

check this out:
http://thatjavathing.blogspot.com/2009/04/extended-persistence-context.html



thanks a lot for your answer.

In fact, an extended persistence context queued operations, until it enters in a transaction context. My question is, can I queued a flush() operation ?

By example I call an EntityManager.flush() method with NOT_SUPPORTED transaction attribute, and next, this method calls another method with a REQUIRED transaction.

Does the flush queued until the extended persistence context entered in a transaction context, or does it just throw a TransactionRequiredException when invoked ?

Thanks

 
Tamas Polgar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I get it.

No, you can not queue it. It immediatelly starts to synchronize the pc with the db. And for this you need a transaction.

But why would you like to queue the flush operation?
 
Laurent Lj
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tamas Polgar wrote:ok, I get it.

No, you can not queue it. It immediatelly starts to synchronize the pc with the db. And for this you need a transaction.

But why would you like to queue the flush operation?


Oh, I just wonder how it works cause I'm soon passing the SCBCD5 exam, so it could be a question...

So it always immediately throw a TransactionRequiredException when no transaction context is active, and this, whatever the persistent context (extended or not).


Thanks a lot
 
Tamas Polgar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
good luck for it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic