users@glassfish.java.net

Re: LAZY INstantiation

From: Kenneth Clark <kenneth_at_rabiddog.co.za>
Date: Fri, 26 Jan 2007 07:07:52 +0200

I will give this a shot when I get a moment.

The error was occurring after deployment, as the entity was being
serialized and passed as a webservice response value. When I run the
local tests there is no webservice deployment so nothing need be
serialized for transmission over a network. I also thought it pretty
weird but the work around seems to have resolved it.

If there is any further info I can give you please let me know and if
you would like the full stack trace I can give that to you as well.

Kenneth Clark
Developer / Analyst

Rabid Dog Laboratories ™
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/


Marina Vatkina wrote:
> It might need further investigation. There is nowhere in the spec
> AFAIK that a collection can't be null or must be initialized in the
> constructor.
>
> Can you test your original test with the latest build?
>
> thanks,
> -marina
>
> Kenneth Clark wrote:
>> 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 ™
>> 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 ™
>>> 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 ™
>>>> 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
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>
>