Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

iBatis and Bidirectional Association

Posts: 15
  • 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 class="B" id="BResult">
<result property="idb" column="idb" />
<result property="parentA" resultMap="AResult" />

And a select

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

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

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
author and cow tipper
Posts: 5000
Hibernate Spring Tomcat Server
  • 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
Posts: 15
  • 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?
Happily living in the valley of the dried frogs with a few tiny ads.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic