-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: self-association - cannot access loading collection error
PostPosted: Sun Nov 21, 2004 5:23 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
Hibernate version: 2.1.6

I am having a "cannot access loading collection" problem as per described in the Hibernate FAQs from the Forum.

http://www.hibernate.org/74.html#A28

From the answer, I have to create another setter (setParentFromApp) to set the parent object. How do I only sets the parent field in setParent()?

Is it something like this?

private setParent(Parent o) {
this.parent.setId = o.getId;
}

public setParentFromApp(Parent o) {
this.parent = o;
}

I have tried the solution described but so far it is not working. It gives me NullPointerException in setParent()

What can I do to fix this? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 5:24 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
setParent() should be:

private setParent(Parent o) {
this.parent.setId(o.getId);
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 10:29 am 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
If you don't have "access=field" attribute in the Hibernate Mapping file for the property "parent" it will always be null! Hibernate access the attribute with the appropiate get/setter.You methods should look like this:
GOOD
Code:
//<!-- Used by Hibernate to set the Parent object -->
public setParent(Parent o) {
this.parent = o;
}

public setParentFromApp(Parent o) {
this.parent = o;
}


ERROR
Code:
//<!-- Error code -->
private (can't be accessed by Hibernate) setParent(Parent o) {
this.parent.id (ERROR: Parent is null) = o.getId();
}
[/b]

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 21, 2004 7:14 pm 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
So basically, I just have to add another setter (setParentFromApp()) and put access="field" in the Hiberante mapping file.

Quote:
have "access=field" attribute in the Hibernate Mapping file for the property "parent"


Is this how you define it?

Code:
<many-to-one
      name="parentCategory"
      class="Category"
      cascade="none"
      outer-join="false"
      update="true"
      insert="true"
      access="field"
      foreign-key="parentCategoryId_fk"
      column="parentCategoryId"
      unique="false"
/>


I did that and I still get "cannot access loading collection" when I try to get the size of the childCategories.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 8:51 am 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Remove the "access=field". it was meant hypothetical.

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 5:47 pm 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
If I use the following code, I can't use cascade="all-delete-orphan" can I?

Quote:
//<!-- Used by Hibernate to set the Parent object -->
public setParent(Parent o) {
this.parent = o;
}

public setParentFromApp(Parent o) {
this.parent = o;
}


I think I tried the above code and it was unsuccessful, I will try again.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 7:12 pm 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
I am sorry, I did not look at the FAQ, just corrected an error in you code.
Can you please supply some more information about what you are doing? Mapping and code between exception?

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject: private public never mind....
PostPosted: Thu Dec 16, 2004 10:00 pm 
Newbie

Joined: Sun Dec 12, 2004 5:52 pm
Posts: 9
setter\getter functions can have any access modifier.

see hibernate reference chapter 4 section 1.1:

Quote:
Properties need not be declared public - Hibernate can persist a property with a default, protected or private get / set pair.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.