I am doing:

          this.transactionBean.invoke(new Transaction() {
                public void invoke() throws Exception {
                    List<Category> categories =
this.shopService.getCategories();
                   // populate form/list
                }
            });

So I am never removing the entities from the transactional code now yet the
call to getCategories is not respecting the lazy loading from the look of
it.  It takes a long time to complete and seems to pull out the full object
graph still.

Thanks

Chris

-----Original Message-----
From: Chris Miles [mailto:[email protected]] 
Sent: 11 December 2010 14:29
To: [email protected]; [email protected]
Subject: RE: Transactions in Embedded OpenEJB

Thanks Jacek.

At the moment my architecture is as follows:

ShopService Local Bean.
ProductService Local Bean.

Within my standalone swing form I fetch products with
shopservice.getCategories() which in turn fetches the list of categories
from the ProductService Bean.

As soon as the list of categories is called from my application it takes a
long time to fetch 5 categories, as it seems it is ignoring the lazy
properties and fetching the full tree

So each category has a list of sub categories which each have a list of
product so every single object is being fetched from the database.

I am assuming that because I am calling shopService from a Swing form which
is outside of the EJB environment this is why it is detaching it.

So in essence what I am trying to do is extend a transaction across the
lifecycle of the swing form. So an entity fetched with one button and then
saved with another button is within the same transaction.

Thanks

Chris

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jacek
Laskowski
Sent: 11 December 2010 13:32
To: [email protected]
Subject: Re: Transactions in Embedded OpenEJB

On Sat, Dec 11, 2010 at 1:07 AM, Chris Miles <[email protected]> wrote:

> I have seen the code example which creates the TransactionBean but 
> that only allows me to scope that block of code into the transaction.
> What I need to be able to do is have a transaction which exists across 
> the lifetime of the form (JFrame) so I can pull Entities out, update 
> them and persist them again.

Hi,

I believe what you're asking is a stateful session bean that will use
extended persistence unit. You'll keep a handle to the bean somewhere in
your code and have a transaction open throughout the bean's lifecycle. It
may also extend the visibility of entities for too long, but it's worth to
give it a try and see whether more tweaks are needed.

You may also use @Lazy annotation to mark simple fields not to be fetched
upon detachment - collection-based fields are by default lazy.

Jacek

--
Jacek Laskowski
Notatnik Projektanta Java EE - http://jaceklaskowski.pl

Reply via email to