users@glassfish.java.net

LAZY INstantiation

From: Kenneth Clark <kenneth_at_rabiddog.co.za>
Date: Thu, 25 Jan 2007 13:14:58 +0200

Hi guys, me again.

I am getting a nasty Toplink error

Caused by: Exception [TOPLINK-7242] (Oracle TopLink Essentials - 2006.8 (Build 060830)): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that lazy relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.

But my Lazy relations ships are initialized as new objects. ie:
  private Collection<Branch> branches = new ArrayList<Branch>();
  private Collection<Director> directors = new ArrayList<Director>();

is inside the class definition and the accessors

  @ManyToMany(targetEntity=DirectorImpl.class, cascade={CascadeType.PERSIST, CascadeType.MERGE})
  @JoinTable( name="organisation_company_has_director",
              joinColumns={_at_JoinColumn(name="organisation_company_id", referencedColumnName="id")},
              inverseJoinColumns={_at_JoinColumn(name="organisation_director_id", referencedColumnName="id")}
            )
  @XmlElement(type=DirectorImpl.class)
        public Collection getDirectors(){
                return this.directors;
        }
        public void setDirectors(Collection directorList){
    this.directors = directorList;
        }
  //-------------------------------------------------------------------------//
  
  @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, targetEntity=BranchImpl.class, mappedBy="company")
  @XmlElement(type=BranchImpl.class)
   public Collection getBranches(){
     return this.branches;
   }
   public void setBranches(Collection value){
     this.branches = value;
   }



Any ideas?

-- 
Kenneth Clark
Developer / Analyst
Rabid Dog Laboratories ^(TM)
Putting the art back into development
*tel:*           +27 11 475 7409
*mobile:*   +27 82 500 5090
*e-mail:*     kenneth_at_rabiddog.co.za
*website:*  http://www.rabiddog.co.za/