ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Larry Meadors" <lmead...@apache.org>
Subject Re: 1:n relations in INSERT statements
Date Tue, 22 Aug 2006 14:25:10 GMT
iBATIS doesn't do that for you.

Depending upon your database, you can do either a stored procedure, or
multiple inserts in one mapped statement, like this example in Oracle:

    <procedure id="insertParentAndChild" parameterMap="pmInsertChipInCash">
        BEGIN
            INSERT INTO MainType (...) VALUES (...);
            INSERT INTO SubType (...) VALUES (...);
        END;
    </procedure>

Larry


On 8/22/06, Andreas Prudzilko <aprudzilko@digitalchocolate.com> wrote:
>
>
>
>
> Hello,
>
>
>
> I know this is a very basic question, so I hope I wasn't just too stupid to
> find the right place to read it up.
>
>
>
> I created a simple Model
>
>
>
> class Project extends GenericObject {
>
>   ..
>
>   Protected Track track;
>
>   …
>
> }
>
>
>
> Now both Project and Track are mapped on tables, where the project table has
> an indexed track_id column for a 1:1 relation between those two.
>
>
>
> I want to insert a new Project to the Db by doing something along the lines
> of this:
>
>
>
> ProductionTrack track = (ProductionTrack)
> client.queryForObject("ProductionTrack.getTrack", 1);
>
> SumeaProject project = new SumeaProject("test", new Date(), new Date(),
> track);
>
> client.insert("Project.insert", project);
>
>
>
> My mapping looks as follows:
>
> ….
>
> <parameterMap id="projectMap"
> class="com.sumea.timemachine.model.SumeaProject">
>
>             <parameter property="id" jdbcType="INT" javaType="int"/>
>
>             <parameter property="name" jdbcType="VARCHAR"
> javaType="java.lang.String"/>
>
>             <parameter property="startDate" jdbcType="DATE"
> javaType="java.util.Date"/>
>
>             <parameter property="endDate" jdbcType="DATE"
> javaType="java.util.Date"/>
>
>             <parameter property="color" jdbcType="INT"
> javaType="java.awt.Color"/>
>
>             <parameter property="track"  ***what comes here?***/>
>
> </parameterMap>
>
>
>
> <insert id="insert"
> parameterClass="com.sumea.timemachine.model.SumeaProject"
> parameterMap="projectMap">
>
>             INSERT INTO
>
>             project (project_id, name, startdate, enddate, color, track_id)
>
>             VALUES (#id#, #name#, #startDate#, #endDate#, #color#, #track#)
>
> </insert>
>
> ….
>
>
>
> Now I wonder how to map the Track object on the track_id (int) column. Do I
> need to write my own TypeHandler for that?
>
>
>
> Thanks for help in advance,
>
>
>
> Andreas
>
>
>
>
>
> Andreas Prudzilko
>
> Tools Developer
>
>
>  Digital Chocolate Ltd
>  Tammasaarenlaituri 3, FI-00180 Helsinki, Finland
>  Fax +358 9 676 301 ▪ Mobile +358 400 855 193
>  Email aprudzilko@sumea.com
>
>
>
>
Mime
View raw message