Results 1 to 4 of 4

Thread: DB mapping not working, leads to infinite loop.

Hybrid View

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    Default DB mapping not working, leads to infinite loop.

    Following are the domain classes :-

    abstract public class A < T > {

    private String item1;
    ....
    private String item2;

    private List < T > itemizedList ;

    <getters and setters>

    }

    class B extends A <B> {

    private String item3;
    ...

    <getters and setters>

    }

    When we try to add the object of class B to database, it gives StackOverFlow error. On debugging we found that its going in infinite loops at AbstractMappingContext ( addPersistentEntity method ) for variable itemizedList.

    When we comment itemizedList related code in domain classes or add @Transient to "private List < T > itemizedList", the object is inserted to DB successfully.

    As classes A and B are part of domain module, we want to avoid the changes for mongo support.

    Is this a bug with spring-data or there any other way to save the object of class B to database?

    Thanks & Regards,
    Last edited by scons; Aug 23rd, 2011 at 12:29 AM. Reason: want to provide more details.

  2. #2
    Join Date
    Aug 2011
    Posts
    1

    Default

    With respect to the above question, I have two domain objects. They are as follows

    Class A{

    String a ,b,c
    List<T> itemizedList;

    getters ane setter methods

    }


    Class B extends A{
    String p,q

    getter and setter methods
    }


    We are creating object for Class B and setting some values to the field in order to insert into MongoDB.

    If we don't set any value to the fields of the Class B, its inserting as Null in the DB. But in case of itemizedList i am getting the Stack overflow error due to infinite looping.

    So to avoid the stackOverflow error, we have comment the itemizedList related codes or used @Transient to the itemizedList field. If so, then the DB update is successfull.

    How to skip the itemizedList field without using the @Transient or comment it and make the DB update successfull.

    I dont't want to make any change the domain classes. Do we need any configuration changes to be done to skip the fields of the domain classes.

    Please clarify if anyone knows the answer to resolve it.

    Thanks in advance
    Last edited by rameezraja; Aug 24th, 2011 at 01:54 AM.

  3. #3
    Join Date
    Aug 2011
    Posts
    2

    Default

    We found a workaround for this. Wrote a converter for class A <T>. Extra fields for class B was converted using instanceof operator. The converter also had the details of how itemized list will be mapped to the db.

    Here the catch was that the itemized list had instances of its own class . Here we made the converter recursive for itemized list, until it was null. We also added @Transient to itemizedList, to prevent implicit conversion to Document.

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Does the problem still persist with M4? If so, would you mind creating a JIRA ticket? Beyond that it would be extremely helpful if you briefly mention the SD module you work with plus the version you use in the very first post .

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •