多対多の自己結合である次の休止状態のマッピングを持つユーザー オブジェクトがあります。
<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>
車のマッピングは次のようになります。
<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>
ユーザー オブジェクトを取得し、次のメソッドを使用して Restlet JSON 表現として返そうとします。
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;
}
問題は、私が得ることStackOverflowError
です:
警告: java.lang.reflect.Method.invoke の sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) の sun.reflect.GeneratedMethodAccessor74.invoke(Unknown Source) のリソース java.lang.StackOverflowError でキャッチされた例外またはエラー(Method.java:597) org.json.JSONObject.populateMap(JSONObject.java:988) で org.json.JSONObject.(JSONObject.java:272) で org.json.JSONObject.wrap(JSONObject.java:1587) ) org.json.JSONArray.(JSONArray.java:158) で org.json.JSONObject.wrap(JSONObject.java:1569) で org.json.JSONObject.populateMap(JSONObject.java:990) で 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) org.json.JSONObject で。populateMap(JSONObject.java:990) at org.json.JSONObject.(JSONObject.java:272)
ユーザー マッピングに設定されている車を削除すると、エラーはなくなり、ユーザーを json に変換できます。無限ループに陥る車のマッピングに何か問題がありますか?