4

My Application uses MongoDb with Spring-Data.

My User.java is as follows.

User{
//other fields
    @DBRef
    List<Request> requests;
    }

Request.java is as follows.

   class Request{
    @Id
    private ObjectId id;
    @DBRef
    private User who;
    @DBRef
    private User whom;
    @DBRef
    private User group;
    }

I am able to save both properly. Say my object user1 contains a list of requests and object request1 contain user1 as value for who. When i retrieve user1 object i am getting StackOverflowError. Details here. Related issue

Are there any workarounds to resolve this other than using Manual references. Are there any other API's that handles cyclic references correctly.

Zaki
  • 6,997
  • 6
  • 37
  • 53
titogeo
  • 2,156
  • 2
  • 24
  • 41
  • Can you explain how that is allegedly related to JPA or JDO or DataNucleus? You're apparently using Spring-Data MongoDB which doesn't use DataNucleus at all, nor JPA, nor JDO. – DataNucleus Sep 10 '12 at 10:33
  • @DataNucleus I am looking if DataNucleus can handle the cyclic dependencies. i saw some references to DataNucleus in the following link https://jira.springsource.org/browse/DATAMONGO-488 .This is the reason i tagged, so that you can tell if I can make use of DataNucleus instead. Sorry for the confusion. – titogeo Sep 10 '12 at 11:18
  • Using DataNucleus with MongoDB has no (reported) problems with such a thing. The user in that issue says he was having cyclic problems with SpringData-Mongo, but when he was using DataNucleus he had no problem of that sort (he had an old problem with something else to do with it that was fixed a while ago). – DataNucleus Sep 10 '12 at 11:35
  • @DataNucleus Thanks. i will do some home work. Will have to see how to migrate existing code. Mean time can you please suggest some references about MongoDb Integration with DataNucleus. – titogeo Sep 10 '12 at 11:36
  • http://www.datanucleus.org/products/accessplatform_3_1/mongodb/support.html but everything is standard JDO/JPA apart from that, so just use general refs for those – DataNucleus Sep 10 '12 at 11:40
  • `@DBRef(lazy = true)` what you need! – Subhrajyoti Majumder Nov 21 '15 at 08:06

1 Answers1

0

Answer : don't use SpringData Mongodb since it has a bug. DataNucleus JDO and DataNucleus JPA have no such bug with bidirectional relations persistence to MongoDB.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • Thanks! Changing to another API is not feasible at this moment. But i will definitely look into this in future. Looking for a work around as of now. And sorry, I cannot accept this as an answer. – titogeo Sep 17 '12 at 09:27