ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toto titi <altrent2...@yahoo.com>
Subject Re: RES: Mapping of one object to several tables?
Date Sun, 24 Apr 2005 12:35:51 GMT
Ok, thank you all for the help.

I had to go with something along the lines (which is
still a very short number of code lines thanks to
iBatis):
1. query the countryTable to get the countryId
2. If it does not exists, insert a new country and
retrieve the id thanks to a selectKey
3. set the countryId in the person object and insert
it


--- Clinton Begin <clinton.begin@gmail.com> wrote:
> Ummm....no.
> 
> There's no way to insert into multiple tables using
> a single
> statement, unless you have DBMS that supports it. 
> The only way I've
> seen this implemented in RDBMS is with a view that
> has insert rules
> applied to it (already very simple designs, that
> don't benefit much
> from the additional simplification).
> 
> Hibernate can't insert into multiple tables with a
> single statement
> any more than it can  solve world hunger or peace on
> earth.
> 
> Clinton
> 
> 
> On 4/22/05, Leonardo Holanda <leo@atlantico.com.br>
> wrote:
> > Yes! Using hibernate :D
> > 
> > -----Mensagem original-----
> > De: Sasha Borodin [mailto:sasha@whoissasha.com]
> > Enviada em: sexta-feira, 22 de abril de 2005 16:43
> > Para: ibatis-user-java@incubator.apache.org
> > Assunto: Re: Mapping of one object to several
> tables?
> > 
> > Can you even do an INSERT that involves multiple
> tables?
> > 
> > -Sasha
> > 
> > > From: Brandon Goodin <brandon.goodin@gmail.com>
> > > Reply-To:
> <ibatis-user-java@incubator.apache.org>
> > > Date: Fri, 22 Apr 2005 13:39:30 -0600
> > > To: <ibatis-user-java@incubator.apache.org>
> > > Subject: Re: Mapping of one object to several
> tables?
> > >
> > > If you are trying to prevent duplicate inserts
> you would need to
> > > perform a select on the database to make sure it
> doesn't exist first.
> > >
> > > Brandon
> > >
> > > On 4/22/05, toto titi <altrent2003@yahoo.com>
> wrote:
> > >> 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
> > >>
> > 
> >
> 

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

Mime
View raw message