java.lang.StackOverflowError

Spring JIRA | Ludovic Praud | 5 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Given two documents which reference each other with a DBRef {code} @Document class Site { @DBRef User admin; } @Document class User { @DBRef Site site; } Site siteSaved = siteRepository.save(new Site()); User userSaved = userRepository.save(new User(siteSaved)); siteSaved.setAdmin(userSaved); siteRepository.save(siteSaved); siteRepository.findOne(siteSaved.id); // stackoverflow here {code} {code} java.lang.StackOverflowError at org.bson.BasicBSONEncoder._put(BasicBSONEncoder.java:417) at org.bson.BasicBSONEncoder.putObjectId(BasicBSONEncoder.java:388) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:188) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:121) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27) at com.mongodb.OutMessage.putObject(OutMessage.java:142) at com.mongodb.OutMessage._appendQuery(OutMessage.java:85) at com.mongodb.OutMessage.query(OutMessage.java:44) at com.mongodb.OutMessage.query(OutMessage.java:38) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:303) at com.mongodb.DBCollection.findOne(DBCollection.java:332) at com.mongodb.DBCollection.findOne(DBCollection.java:318) at com.mongodb.DBRefBase.fetch(DBRefBase.java:52) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue(MappingMongoConverter.java:950) at org.springframework.data.mapping.model.BeanWrapper.<init>(BeanWrapper.java:115) at org.springframework.data.mapping.model.BeanWrapper.create(BeanWrapper.java:73) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:217) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:712) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$2.doWithAssociation(MappingMongoConverter.java:239) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:185) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:236) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue(MappingMongoConverter.java:950) at org.springframework.data.mapping.model.BeanWrapper.<init>(BeanWrapper.java:115) at org.springframework.data.mapping.model.BeanWrapper.create(BeanWrapper.java:73) {code} As a workaround I can break this cycle and only reference Site from User and add an isAdmin property to User class but I think it is less direct and clear this way. It requires one more query to retrieve the admin of a Site. I fell that it is because retrieving a document from DBRef is not lazy as asked in DATAMONGO-348, but I thought it was eager only for one level depth.

    Spring JIRA | 5 years ago | Ludovic Praud
    java.lang.StackOverflowError
  2. 0

    Given two documents which reference each other with a DBRef {code} @Document class Site { @DBRef User admin; } @Document class User { @DBRef Site site; } Site siteSaved = siteRepository.save(new Site()); User userSaved = userRepository.save(new User(siteSaved)); siteSaved.setAdmin(userSaved); siteRepository.save(siteSaved); siteRepository.findOne(siteSaved.id); // stackoverflow here {code} {code} java.lang.StackOverflowError at org.bson.BasicBSONEncoder._put(BasicBSONEncoder.java:417) at org.bson.BasicBSONEncoder.putObjectId(BasicBSONEncoder.java:388) at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:188) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:121) at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86) at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27) at com.mongodb.OutMessage.putObject(OutMessage.java:142) at com.mongodb.OutMessage._appendQuery(OutMessage.java:85) at com.mongodb.OutMessage.query(OutMessage.java:44) at com.mongodb.OutMessage.query(OutMessage.java:38) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:303) at com.mongodb.DBCollection.findOne(DBCollection.java:332) at com.mongodb.DBCollection.findOne(DBCollection.java:318) at com.mongodb.DBRefBase.fetch(DBRefBase.java:52) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue(MappingMongoConverter.java:950) at org.springframework.data.mapping.model.BeanWrapper.<init>(BeanWrapper.java:115) at org.springframework.data.mapping.model.BeanWrapper.create(BeanWrapper.java:73) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:217) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:712) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$2.doWithAssociation(MappingMongoConverter.java:239) at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:185) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:236) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200) at org.springframework.data.mongodb.core.convert.MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue(MappingMongoConverter.java:950) at org.springframework.data.mapping.model.BeanWrapper.<init>(BeanWrapper.java:115) at org.springframework.data.mapping.model.BeanWrapper.create(BeanWrapper.java:73) {code} As a workaround I can break this cycle and only reference Site from User and add an isAdmin property to User class but I think it is less direct and clear this way. It requires one more query to retrieve the admin of a Site. I fell that it is because retrieving a document from DBRef is not lazy as asked in DATAMONGO-348, but I thought it was eager only for one level depth.

    Spring JIRA | 5 years ago | Ludovic Praud
    java.lang.StackOverflowError

    Root Cause Analysis

    1. java.lang.StackOverflowError

      No message provided

      at org.bson.BasicBSONEncoder._put()
    2. MongoDB Java Driver
      DBRefBase.fetch
      1. org.bson.BasicBSONEncoder._put(BasicBSONEncoder.java:417)
      2. org.bson.BasicBSONEncoder.putObjectId(BasicBSONEncoder.java:388)
      3. org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:188)
      4. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:121)
      5. org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86)
      6. com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
      7. com.mongodb.OutMessage.putObject(OutMessage.java:142)
      8. com.mongodb.OutMessage._appendQuery(OutMessage.java:85)
      9. com.mongodb.OutMessage.query(OutMessage.java:44)
      10. com.mongodb.OutMessage.query(OutMessage.java:38)
      11. com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:303)
      12. com.mongodb.DBCollection.findOne(DBCollection.java:332)
      13. com.mongodb.DBCollection.findOne(DBCollection.java:318)
      14. com.mongodb.DBRefBase.fetch(DBRefBase.java:52)
      14 frames
    3. Spring Data MongoDB - Core
      MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue
      1. org.springframework.data.mongodb.core.convert.MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue(MappingMongoConverter.java:950)
      1 frame
    4. Spring Data Core
      BeanWrapper.create
      1. org.springframework.data.mapping.model.BeanWrapper.<init>(BeanWrapper.java:115)
      2. org.springframework.data.mapping.model.BeanWrapper.create(BeanWrapper.java:73)
      2 frames
    5. Spring Data MongoDB - Core
      MappingMongoConverter$2.doWithAssociation
      1. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:217)
      2. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200)
      3. org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:712)
      4. org.springframework.data.mongodb.core.convert.MappingMongoConverter$2.doWithAssociation(MappingMongoConverter.java:239)
      4 frames
    6. Spring Data Core
      BasicPersistentEntity.doWithAssociations
      1. org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:185)
      1 frame
    7. Spring Data MongoDB - Core
      MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue
      1. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:236)
      2. org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:200)
      3. org.springframework.data.mongodb.core.convert.MappingMongoConverter$DelegatingParameterValueProvider.getParameterValue(MappingMongoConverter.java:950)
      3 frames
    8. Spring Data Core
      BeanWrapper.create
      1. org.springframework.data.mapping.model.BeanWrapper.<init>(BeanWrapper.java:115)
      2. org.springframework.data.mapping.model.BeanWrapper.create(BeanWrapper.java:73)
      2 frames