• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

iBatis Mapping Help

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Dave Tuttle
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic