ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Prudzilko" <aprudzi...@digitalchocolate.com>
Subject 1:n relations in INSERT statements
Date Tue, 22 Aug 2006 14:17:25 GMT


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",

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?***/>



<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#)




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 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 <mailto:aprudzilko@sumea.com> 



View raw message