RE: Transactions in Embedded OpenEJB (Lazy Loading issue)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

RE: Transactions in Embedded OpenEJB (Lazy Loading issue)

Chris Miles
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:[hidden email]]
Sent: 11 December 2010 14:29
To: [hidden email]; [hidden email]
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: [hidden email] [mailto:[hidden email]] On Behalf Of Jacek
Laskowski
Sent: 11 December 2010 13:32
To: [hidden email]
Subject: Re: Transactions in Embedded OpenEJB

On Sat, Dec 11, 2010 at 1:07 AM, Chris Miles <[hidden email]> 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 | Threaded
Open this post in threaded view
|

Re: Transactions in Embedded OpenEJB (Lazy Loading issue)

Jacek Laskowski
On Sat, Dec 11, 2010 at 6:31 PM, Chris Miles <[hidden email]> wrote:

> 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.

Nothing comes to my mind having seen the snippet. I've got more
questions and no answers, and guess I would have to create a test case
to see it in action and propose a solution.

Would you mind if I asked you for a simple test case to reproduce the
issue? I'd appreciate it very much.

Jacek

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