ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ingmar Lötzsch <iloetz...@asci-systemhaus.de>
Subject Re: KeyProperty attribute in Selectkey Tag
Date Fri, 13 Feb 2009 08:17:43 GMT
> Well I do have sequences defined for my each table which acts as a 
> primary key for my table now I want to use this generatedkey as a 
> foreign key in another table so now if I use my class attribute to have 
> this sequence id , then how can I get that key in java code , I am 
> assuming I can do in following manner please tell me if I a, doing in a 
> right way or not (my DB is Postgres).
> 
> <insert id="MSCPerfCntrTrunkTblImpl"
> parameterClass="com.hns.hss.nmf.server.log.manager.gensrc.MSCPerformance.impl.MSCPerfCntrTrunkTblImpl">
>       <selectKey keyProperty="generatedSequenceId_0" resultClass="int">
>       SELECT nextval('MSCPerfCntrTrunk_seq')
>     </selectKey>
>       insert into MSCPerfCntrTrunkTbl(
> seq_no,
>       neinfo_id,
>       rectimeStamp,
>       transactionId,
>       destNum_2,
>       )
> values
>       (
>       #generatedSequenceId_0#,
>       #neInfoId_0#,
>       #timeStamp_0#,
>       #transactionId_1.value#,
>       #count_2.value#,
>       )
> 
> And in my  java code  if I am writing following statements
> 
> SqlMapClient.insert(“MSCPerfCntrTrunkTblImpl”,ObjectpointingtoMSCPerfCntrTrunkTblImpl)

You have two possibilities:

1.

ObjectpointingtoMSCPerfCntrTrunkTblImpl o = ...
SqlMapClient.insert("MSCPerfCntrTrunkTblImpl", o);
Integer id = o.getGeneratedSequenceId_0();

2.

ObjectpointingtoMSCPerfCntrTrunkTblImpl o = ...
Integer id = SqlMapClient.insert("MSCPerfCntrTrunkTblImpl", o);

Ingmar

Mime
View raw message