Announcement Announcement Module
Collapse
No announcement yet.
[MongoDB] StackOverflowError if document contains non-static transient logger Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [MongoDB] StackOverflowError if document contains non-static transient logger

    Hi,

    I'm encountering StackOverflowError [2] when saving my mongo document that contains a transient slf4j logger. Sample model [1]. I'm using spring-data-mongodb 1.1.1.RELEASE, this does not occur in spring-data-mongodb 1.1.0.M1. Error disappears if I annotate my logger with spring-data @Transient.

    Is this a bug or is the transient keyword not enough to exclude the field?

    Thanks and let me know if you need more details.

    [1]
    Code:
    @Document(collection = "FOO_BAR")
    public class FooBarMongoRecord {
    
        private transient final Logger _LOG = LoggerFactory.getLogger(FooBarMongoRecord.class);
    
        @Id
        private String id;
    
        private Long version;
    
        // Getters/setters removed
    }
    [2]
    Code:
    java.lang.StackOverflowError
    	at java.util.HashMap$EntryIterator.<init>(HashMap.java:832)
    	at java.util.HashMap$EntryIterator.<init>(HashMap.java:832)
    	at java.util.HashMap.newEntryIterator(HashMap.java:846)
    	at java.util.HashMap$EntrySet.iterator(HashMap.java:950)
    	at java.util.AbstractMap.hashCode(AbstractMap.java:459)
    	at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336)
    	at org.springframework.data.util.TypeDiscoverer.hashCode(TypeDiscoverer.java:457)
    	at org.springframework.data.util.ClassTypeInformation.hashCode(ClassTypeInformation.java:39)
    	at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768)
    	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:172)
    	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:69)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:439)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:442)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:517)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:477)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:408)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:442)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:517)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:477)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:408)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:442)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:517)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:477)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:408)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:442)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:517)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:477)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:408)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:442)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:376)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:363)
    	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:195)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:363)
    	at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:334)
    Last edited by aco; Oct 24th, 2012, 09:58 PM.

  • #2
    I had this SAME issue. It is related to QueryDSL. Upgrade to 2.8.1 - it was addressed in that release. (or remove it if you are not using it).

    Comment


    • #3
      Why would you want to use a non-static logger?

      Comment


      • #4
        Oops. Maybe this was not the issue I had. Sorry - Did not read the stack trace. Mine was during the QueryDSL APT process with a static logger - which has been fixed in 2.8.1. Sorry!

        Oliver - Congrats on the book. Picked mine up on Kindle the other day. Once I get some cylces, I'm going write a few blog posts about how we are using Spring Data Mongo & Spring Data Neo4j with Spring Remoting to Jruby. Fun stuff.

        M

        Comment


        • #5
          Hi,

          Sorry for the late response on this.

          For my usecase, I actually had a super class for all my models that provides different logging level for each object state:

          Code:
          public abstract class AbstractModel {
          
              protected final transient Logger _LOG = LoggerFactory.getLogger(getClass());
          
              @Override
              public final String toString() {
                  if (getLogger().isTraceEnabled()) {
                      return printTrace();
          
                  } else if (getLogger().isDebugEnabled()) {
                      return printDebug();
          
                  } else {
                      return printInfo();
                  }
              }
          
              @Override
              public String printInfo() {
                  return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
                          .toString();
              }
          
              @Override
              public String printDebug() {
                  return printInfo();
              }
          
              @Override
              public String printTrace() {
                  return printDebug();
              }
          }
          My subclasses, can then choose to override any of the printTrace, printDebug, printInfo methods to display summary view or comprehensive view of the object state. I had to use a non-static logger to retrieve the actual class of the subclass for logging control.

          Does this make sense or not at all?

          Comment

          Working...
          X