On Mon, Apr 28, 2008 at 11:11 AM, Martin Homik <[EMAIL PROTECTED]> wrote:
>
>  I actually tried to solve the problem by using OGNL.
>
>  <s:iterator value="myGroups">
>     Group name: <s:property value="name"/>
>     Size: <s:property value='members.size()'/> members
>  </s:iterator>
>
>  In my second attempt, I called a non-property method:
>
>  In JSP:
>  ...
>     Size: <s:property value='membersSize()'/> members
>  ...
>  In POJO:
>         @Transient
>         public int getMembersSize() {
>                 return members.size();
>         }
>
>
>  In both cases I ended up with a LazyInitializationException.

That's because you're not solving anything by pushing the call down
deeper. it's *when* you make the call that is broken, not *where*.
You're thread is no longer inside the DB transaction by the time
you're rendering your page. You need to calculate the size before you
leave the transaction... which is probably in your action.

As I say though - be aware of how much work you're asking Hibernate to
perform by calling .size(). This is not practical and you're better
off maintaining a count on your Group object and persisting that in
the DB. Think about it... it's a lot of work to count all those
members every time! Your application will never scale if you don't
think about these things ahead of time.

Matt is suggesting that you uncomment the OpenSessionInViewFilter so
that the DB session is still alive when the thread is rendering your
page. That might work, but it is not a good solution in this case.

Unless... I'm missing something w.r.t. some devious Hibernate proxy
that automatically maintains a count for you under the covers. I
highly doubt it does this though.

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

Reply via email to