Stackoverflow when querying a document with a loop reference using @DBRef

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 can save both correctly. Say my object user1 contains a list of queries and a query for object1 that contains user1 as the value for whom. When I get the user1 object, I get a StackOverflowError. More details here . Related question

Are there any workarounds for this solution other than using the manual links . Is there any other API that handles circular references correctly.

+4
source share
1 answer

Answer: do not use SpringData Mongodb, as it has an error. DataNucleus JDO and DataNucleus JPA do not have this bug with the persistence of bidirectional relations to MongoDB.

0
source

Source: https://habr.com/ru/post/1432896/


All Articles