• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

iBatis Mapping Help

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a hard time figuring out how to build my mapping file(s) to support this and query correctly.





DB Tables

item
----------
item_id
title
description
image_loc

type
---------
type_id
type

item_type
-------------
item_id
type_id

Now the data in item_type might look something like
1 - 1
1 - 2
1 - 3

So item_id 1 would have types 1,2,and 3.

I can populate Item and I can populate Type. I even know how to map for a List of objects but only when I am dealing with 2 tables where one table has a FK to the other table. What I can't seem to figure out is how to get the List of types populated for my Item object when I have the 3rd relation table. Any help is appreciated.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's really a sql question, not ibatis.
You seem to have a one-to-many relationship, so you don't actually need the mapping table.
However, to list types for an item id you have to join the type table and the item_type table. I'm no sql guru so I'm not sure of the best join syntax, but it's something like:
select ... from type a, item_type b where a.type_id = b.type_id and b.item_id = <some item id>
--Dave
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic