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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

iBatis and Bidirectional Association

 
Greenhorn
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>

<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
 
author and cow tipper
Posts: 5000
1
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
Greenhorn
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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic