On Mon, Apr 28, 2008 at 8:16 AM, Martin Homik <[EMAIL PROTECTED]> wrote:
>
>  Problem:
>   * I have a "Group" POJO which keeps a list of its "members" (ManyToMany
>  relation).
>   * The GroupAction class stores a list of my current groups and it has a
>  group field for
>      accessing information of a single group. In principle, the stucture is
>  very similar to the
>      PersonAction of the online tutorial.
>
>  Question: In the JSP, I iterate through the groups and print some group
>  information. For each group, I'd like to print the number of members. How do
>  I get it?  Can I access somehow members.size() in the JSP? Or am I on a
>  completely wrong path?

In order to call size() on your list of members, I believe Hibernate
needs to fully populate the List with every Person who is a member -
or at least a lazy loaded proxy object for each Person object. That
means every single member object has to be constructed for each member
from the DB - just so you can get a count. I.e. Very very wasteful! If
you're no longer inside the DB transaction, you can't query this and
will get the LazyInitializationException - you really don't want to do
that anyway.

You could just maintain a count of the number of members in each
group. This is all you need to query when you want the member count.
Also, I would be careful about what you store as a reference to each
member. Personally, I'd just store the ID of each person so it is very
explicit when I want to load the actual Person object.

>
>  Note: I tried a few things by try-and-error and sometimes I ended up with a
>  Hibernate LazyInitializationException. Now, I just don't know at what end to
>  continue? Is it something that
>  i) can be solved simply via JSP and some expression, or
>  ii) do I have to do something in the Action class, or
>  iii) does it go further down into the persistence layer?
>
>  Hope, my mail is not too short and you understand my problem.
>  --
>  View this message in context: 
> http://www.nabble.com/How-to-access-collection-fields-in-Struts2--tp16941170s2369p16941170.html
>  Sent from the AppFuse - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to