ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mkhitaryan, Aram" <Aram.Mkhitar...@lycos-europe.com>
Subject RE: 1:n relations in INSERT statements
Date Wed, 23 Aug 2006 04:25:26 GMT
IBATIS mappings are with expression language support.

You can access bean properties via dots, which means that

if your SumeaProject has public getTrack and setTrack in your mappings you can use “track.track_id”
as property name.

From your code it follows that you have to create public setter and getter for your Track
in Project and track_id in Track.

 

Best,

Aram

 

________________________________

From: Andreas Prudzilko [mailto:aprudzilko@digitalchocolate.com] 
Sent: Tuesday, August 22, 2006 7:17 PM
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