[jboss-user] [JBoss Seam] - LazyInitialization and ScopeType.SESSION question

pwoj do-not-reply at jboss.com
Tue Sep 11 04:25:05 EDT 2007


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


@Scope(ScopeType.SESSION)
  | @Name("account")
  | @Entity
  | 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":

@Name("authenticator")
  | 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:

  | @Name("someManager")
  | public class SomeManager () {
  |  @In Account currentAccount;
  |   
  |   public void doSth() {
  |      for (Operation operation:currentAccount.getOperations()) {
  |          log.debug(operation);
  |      }
  |   }
  | }

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 :
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=85964

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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4082876#4082876

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4082876



More information about the jboss-user mailing list