2 Replies Latest reply on Sep 11, 2007 5:46 AM by Pete Muir

    LazyInitialization and ScopeType.SESSION question

    Przemysław Wojewódka Newbie

      Let's say I have entity class that is also seam component named "account":

      public class Account implements Serializable{
       private Long id;
       private Collection<Operation> operations;

      During log in operation I read user account object from db and outjected under name "currentAccount":

      public class Authenticator {
      @Out(required=false, scope=ScopeType.SESSION, value="currentAccount")
       private Account account;
       public boolean authenticate() {
       account = getUserAccountFromDB();

      Now I want to use currentAccount object in diffrent manager(plain pojo), for instance:
      public class SomeManager () {
       @In Account currentAccount;
       public void doSth() {
       for (Operation operation:currentAccount.getOperations()) {

      And now currentAccount.getOperations() will cause org.hibernate.LazyInitializationException the same if I try use use sth like #{currentAccount.operations} directly in view.

      I came across :

      where Gavin King posted that It's neccesary to reattach detached object (scoped SESSION) using session.lock() to make it valid to conversation context.

      And now my qustions:
      1. Do I really have to do this "reattach" in every bean that uses SESSION scoped seam components?
      2. If I use many views that displays SESSION scoped objects (complex lazy initialization) I have to make them EAGER ??? (imagine there is outjection at the begginig and then only views that uses SESSION scoped components - no other beans)
      3. Why @In does not make this "attach" automatically?

      I'm just at the begging of seam developing process and maybe I miss some important point? ;)

      Many thanks in advance