• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

iBatis and Bidirectional Association

 
Ro Ah
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
My problem is that I am trying to represent a bidirectional association relationship using “iBatis”. Suppose this problem:
Java Classes:
class A {String ida; List<B> bs;}
class B {String idb; A parentA;}

Database Structure
a( ida [PK])
b( idb [PK], ida [FK] )

And the relation between a-> b is one-to-many (A has 0..* B)

And iBatis Maps
<resultMap class="A" id="AResult" groupBy="ida">
<result property="ida" column="ida" />
<result property="bs" resultMap="BResult" />
</resultMap>

<resultMap class="B" id="BResult">
<result property="idb" column="idb" />
<result property="parentA" resultMap="AResult" />
</resultMap>

And a select

<select id="getA" resultMap="AResult">
SELECT
A.ida as ida,
B.idb as idb,
FROM A A, B B
WHERE
A.ida = B.ida
and A.ida = #value#
</select>

Now, When I try to run “getA” select statement I get an exception:
java.lang.StackOverflowError
at sun.nio.cs.UTF_8$Decoder.decodeArrayLoop(UTF_8.java:270)
at sun.nio.cs.UTF_8$Decoder.decodeLoop(UTF_8.java:416)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:544)
at java.lang.StringCoding$CharsetSD.decode(StringCoding.java:190)
at java.lang.StringCoding.decode(StringCoding.java:228)
at java.lang.String.<init>(String.java:405)

This will work if I removed “<result property="parentA" resultMap="AResult" /> “ this line from B map. But this will make the generated B.paretnA property with null value

So, what is the best way I can use to overcome this problem? And Sorry for the long mail 
Any help is appreciated

NOTE: I can’t use another tecnology
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the java.lang.StackOverflowError is from creating a circular relationship that becomes infinitely recursive. Flattening it out should solve the problem.

-Cameron McKenzie
 
Ro Ah
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But in that case more calls to the backend will be made, What is the most efficent way to break this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic