Skip to main content

Stack Overflow with Glassfish V2 B20

6 replies [Last post]
cprashantreddy
Offline
Joined: 2004-04-19

Hi,

I get a stack over flow error when i am trying to persist an Object Model using Glassfish V2 B20.

The object model is fairly simple and has one-to-many and manyto-many relationship. I am also using EAGER FetchType.

Following is the stack trace :

Exception in thread "main" java.lang.StackOverflowError
at java.util.HashMap$KeyIterator.(HashMap.java:821)
at java.util.HashMap$KeyIterator.(HashMap.java:821)
at java.util.HashMap.newKeyIterator(HashMap.java:835)
at java.util.HashMap$KeySet.iterator(HashMap.java:867)
at java.util.HashSet.iterator(HashSet.java:154)
at oracle.toplink.essentials.internal.queryframework.CollectionContainer
Policy.iteratorFor(CollectionContainerPolicy.java:157)
at oracle.toplink.essentials.mappings.CollectionMapping.iterateOnRealAtt
ributeValue(CollectionMapping.java:634)
at oracle.toplink.essentials.internal.indirection.IndirectionPolicy.iter
ateOnAttributeValue(IndirectionPolicy.java:207)
at oracle.toplink.essentials.internal.indirection.TransparentIndirection
Policy.iterateOnAttributeValue(TransparentIndirectionPolicy.java:289)
at oracle.toplink.essentials.mappings.ForeignReferenceMapping.iterate(Fo
reignReferenceMapping.java:551)
at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.iterate(
ObjectBuilder.java:2020)
at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.ite
rateReferenceObjects(DescriptorIterator.java:296)
at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.ite
rateReferenceObjectForMapping(DescriptorIterator.java:287)
at oracle.toplink.essentials.mappings.CollectionMapping.iterateOnElement
(CollectionMapping.java:621)
at oracle.toplink.essentials.mappings.CollectionMapping.iterateOnRealAtt
ributeValue(CollectionMapping.java:635)
at oracle.toplink.essentials.internal.indirection.IndirectionPolicy.iter
ateOnAttributeValue(IndirectionPolicy.java:207)
at oracle.toplink.essentials.mappings.ForeignReferenceMapping.iterate(Fo
reignReferenceMapping.java:551)
at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.iterate(
ObjectBuilder.java:2020)
at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.ite
rateReferenceObjects(DescriptorIterator.java:296)
at oracle.toplink.essentials.internal.descriptors.DescriptorIterator.ite
rateReferenceObjectForMapping(DescriptorIterator.java:287)
at oracle.toplink.essentials.mappings.CollectionMapping.iterateOnElement
(CollectionMapping.java:621)
at oracle.toplink.essentials.mappings.CollectionMapping.iterateOnRealAtt
ributeValue(CollectionMapping.java:635)
at oracle.toplink.essentials.internal.indirection.IndirectionPolicy.iter
ateOnAttributeValue(IndirectionPolicy.java:207)
at oracle.toplink.essentials.internal.indirection.TransparentIndirection
....so on..

Any ideas ?
Thank you
-Prashant

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cprashantreddy
Offline
Joined: 2004-04-19

> If i comment out line 4, b.getA() will return empty list.

It looks like[1] Toplink maintains a cache which has to be turned off in a @QueryHint to suggest loading fresh from Database.

But still I would not like to do this hinting, and maintain consistent in-memory object model, by doing the right thing on owning side and inverse side of the bi-directional relationship. Hence now the StackOverflow exception condition becomes critical issue.

Please help.
-Prashant
[1]http://weblogs.java.net/blog/guruwons/archive/2006/09/understanding_t_1.html

gyorke
Offline
Joined: 2005-06-21

Is the code you posted exactly like your testcase? You mention that your relationships are EAGER but the posted example has LAZY relationships?
Can you fill a glassfish issue an upload your testcase?
--Gordon

pkrogh
Offline
Joined: 2005-10-19

It is hard to say how this could be caused without more information on the model.

Could you provide a small reproduction?

cprashantreddy
Offline
Joined: 2004-04-19

I am working on providing a reproduction. Some details i forgot to mention about the set up are.

1. Using JPA in standalone mode. Not inside a container.
2. Stack overflow does not happen right away, when i try to persist one instance of the object. When i try to persist several (thousands) of instances one after another, CPU usage max'es out and eventually Stack overflow is thrown.

cprashantreddy
Offline
Joined: 2004-04-19
cprashantreddy
Offline
Joined: 2004-04-19

>Now I have another question not related to Stack overflow :
>If i have a bi-directional relationship, does JPA/Spec >require me to do both line 4, and 5.

Ok, so the Spec does say that i have to keep the inverse side of the relationship consistent with owning side.

This means that code at line numbers 4,5 must both be there.

But the problem is if i put in line no:4 I get a stack overflow.

Is this a known issue.? Any ideas?