Uri Lukach
Uri Lukach

Reputation: 1121

MongoDB - Spring - Saving an object causes StackOverflowError

Our architecture combines Spring with MongoDB. We usually do not have any issues with saving/editing and reading custom objects. Lately we have ran a few modifications in which we started getting the following errors

       java.lang.StackOverflowError
at java.util.Collections.emptyList(Collections.java:2959)
at org.springframework.data.util.TypeDiscoverer.getTypeArguments(TypeDiscoverer.java:442)
at org.springframework.data.util.ClassTypeInformation.getTypeArguments(ClassTypeInformation.java:40)
at org.springframework.data.util.TypeDiscoverer.getActualType(TypeDiscoverer.java:288)
at org.springframework.data.util.ClassTypeInformation.getActualType(ClassTypeInformation.java:40)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.addCustomTypeKeyIfNecessary(MappingMongoConverter.java:650)

Or

        java.lang.StackOverflowError
at sun.misc.Unsafe.getObject(Native Method)
at sun.misc.Unsafe.getObject(Unsafe.java:231)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:19)
at java.lang.reflect.Field.get(Field.java:358)
at org.springframework.util.ReflectionUtils.getField(ReflectionUtils.java:118)
at org.springframework.data.mapping.model.BeanWrapper.getProperty(BeanWrapper.java:133)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:382)

Before I'm adding all the major classes that combines our architecture I wonder whether any of you have previously encountered these kind of exceptions?

Upvotes: 5

Views: 4570

Answers (2)

user5349489
user5349489

Reputation: 1

I have faced this issue while fetching document from mongo database using findById method so as workaround you can use another alternatives supported mongoTemplate find methods .

Thanks.

Upvotes: 0

Uri Lukach
Uri Lukach

Reputation: 1121

Apparently I can not add logger to my data objects,

when I removed the logger it started working again

protected final Log logger = LogFactory.getLog(getClass());

Be careful when using loggers in your data object in MongoDB

It seems that using @Transient should signal MongoDB driver not to persist the logger variable

http://docs.spring.io/spring-data/data-document/docs/current/reference/html/#mapping-usage-annotations

Upvotes: 9

Related Questions