Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9084419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:59:38+00:00 2026-06-16T20:59:38+00:00

I have a user object with the following hibernate mapping which is a many

  • 0

I have a user object with the following hibernate mapping which is a many to many self join:

    <hibernate-mapping>
        <class name="User" table="User">
            <id name="id" type="int">
            <column name="userId" />
                <generator class="native" />
            </id>
            <set name="friends" table="User_Friend" 
                    inverse="false" lazy="true" cascade="all">
                <key column="userId"/>
                <many-to-many column="friendId" class="User" />
            </set>
            <set name="cars" table="Car" inverse="true" fetch="select" lazy="true">
            <key>
                <column name="userId" not-null="true" />
            </key>
            <one-to-many class="Car" />
        </set>
        </class>
    </hibernate-mapping>

The car mapping looks like the following:

<hibernate-mapping>
    <class name="Car" table="Car">
        <id name="id" type="int">
            <column name="carId" />
            <generator class="native" />
        </id>
        <set name="carStatuses" table="Car_Status" 
                inverse="true" lazy="true" fetch="select">
            <key>
                <column name="carId" not-null="true" />
            </key>
            <one-to-many class="CarStatus" />
        </set>
        <many-to-one name="user" 
        column="userId"
        not-null="true"/>

    </class>
</hibernate-mapping>

I retrieve the user object and then attempt to return it as a Restlet JSON Representation with this method:

public Representation getJSONRepresentationFromObject(User object) {


    JSONArray ja = new JSONArray();
    JSONObject jo = new JSONObject(object);

    ja.put(jo);

    JsonRepresentation jr = new JsonRepresentation(ja);
    jr.setCharacterSet(CharacterSet.UTF_8);

    return jr;
}

The problem is that I get a StackOverflowError:

WARNING: Exception or error caught in resource
java.lang.StackOverflowError at
sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.json.JSONObject.populateMap(JSONObject.java:988) at
org.json.JSONObject.(JSONObject.java:272) at
org.json.JSONObject.wrap(JSONObject.java:1587) at
org.json.JSONArray.(JSONArray.java:158) at
org.json.JSONObject.wrap(JSONObject.java:1569) at
org.json.JSONObject.populateMap(JSONObject.java:990) at
org.json.JSONObject.(JSONObject.java:272) at
org.json.JSONObject.wrap(JSONObject.java:1587) at
org.json.JSONArray.(JSONArray.java:158) at
org.json.JSONObject.wrap(JSONObject.java:1569) at
org.json.JSONObject.populateMap(JSONObject.java:990) at
org.json.JSONObject.(JSONObject.java:272)

If I remove the cars set in the user mapping the error goes away and I am able to convert the user to json. Is there something wrong with the car mapping that throws it into an infinite loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:59:39+00:00Added an answer on June 16, 2026 at 8:59 pm

    The problem was that the Car object has a back reference to the User/ Friend object. I solved this problem here:

    Hibernate Object not detaching

    Answer: pull object from hibernate. Create separate java object. Loop through objects and populate newly created objects with hibernate object values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following @OneToOne relation: @Entity @Table(name=USER) public class User implements Serializable{ private
Following scenario: I have user object: ... @Column(name = TITLE) private String title; @NotNull
I have a object User and it is the following class: public class User
Yo i have the following nhibernate class: public class User { public virtual int
I have a parent-child relationship: @Entity @Table(name = user) public final class User {
Let's say I have following POJO's using Hibernate. public class User { private String
I have the following code that loads a user's Active Directory DirectoryEntry object from
I have the following user resource: class UserResource(ModelResource): class Meta: queryset = User.objects.all() resource_name
I have an user object for my restful service, which has an userid and
I have a script which creates a user-defined object like this: obj = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.