users@glassfish.java.net

Re: LAZY INstantiation

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

Okay I think I have found a solution.

Instantiating the Collection objects inside the default constructor
resolved the issue.

The instantiation of the objects is needed as null can't be serialized.

Hence the reason it was working in my standalone test which had no
serialization it. I get the feeling this is probably mentioned in some
spec somewhere.

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/


Kenneth Clark wrote:
> Update:
>
> Inside my standalone test case I am not getting the below mentioned
> error. The error also disappears when the fetch is set to FetchType.EAGER.
>
> Is this a bug? I noted on the forums where this question was asked
> that there was no error.
>
> 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/
>
>
> Kenneth Clark wrote:
>> 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/
>> ------------------------------------------------------------------------
>>
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.5.432 / Virus Database: 268.17.10/651 - Release Date: 24/01/2007 18:48
>>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.432 / Virus Database: 268.17.10/651 - Release Date: 24/01/2007 18:48
>