ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andreas Prudzilko" <aprudzi...@digitalchocolate.com>
Subject RE: 1:n relations in INSERT statements
Date Tue, 22 Aug 2006 14:46:03 GMT
My Track object is already stored, so I just wondering how to access the id value (#track.id#)

 

Thanks, that was what I was looking for – works splendid now.

 

 

 

 

 

________________________________

From: Niels Beekman [mailto:n.beekman@wis.nl] 
Sent: 22. elokuuta 2006 17:38
To: user-java@ibatis.apache.org
Subject: RE: 1:n relations in INSERT statements

 

As Larry mentioned, you should persist the track separately.

 

Be sure to use either the combination parameterMap+? or parameterClass+#, more details in
the developers guide.

 

Use either:

 

<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.id" jdbcType="INT"/>

</parameterMap>

 

<insert id="insert" parameterMap="projectMap">

            INSERT INTO

            project (project_id, name, startdate, enddate, color, track_id)

            VALUES (?, ? , ? , ? , ? , ?)

</insert>

 

or:

 

<insert id="insert" parameterClass="com.sumea.timemachine.model.SumeaProject">

            INSERT INTO

            project (project_id, name, startdate, enddate, color, track_id)

            VALUES (#id#, #name#, #startDate#, #endDate#, #color#, #track.id#)

</insert>

 

Also, specification of jdbcType and javaType is mostly unnecessary, first try without them,
if you get errors, add them.

 

HTH,

 

Niels

 

________________________________

From: Andreas Prudzilko [mailto:aprudzilko@digitalchocolate.com] 
Sent: dinsdag 22 augustus 2006 16:17
To: user-java@ibatis.apache.org
Subject: 1:n relations in INSERT statements

 

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

 

 

Mime
View raw message