ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toto titi <altrent2...@yahoo.com>
Subject Mapping of one object to several tables?
Date Fri, 22 Apr 2005 19:20:38 GMT
Hello,

I am new to iBatis/SQL and don't really know if the
following is possible or not.. Also, I am not sure
where to ask this question as I don't know if it
relates more to iBatis or SQL... so please bear with
me.

Let's say I want to save the following object:
class person {
   String name;
   String country;
}

In order to save space in my db I will save the
country in a table of its own and refer to each record
from the name table by an id:

personTable
-----------
id
name
countryId


countryTable
------------
id
country



Now, I know that for a select statement I can just do
a join to get my object back:
SELECT name, country from personTable, countryTable
where countryId=countryTable.id;

My question is, how do I insert a new person in these
two tables with only one query? Taking into account
that the country for the new person object might
already have been inserted..

Thanks for any help!

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Mime
View raw message