Hey Bruke,
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)
Above statement will return an Object but an object of what type??.
Looking forward to your response.
Regards
Rahul Saluja
________________________________
From: Burke.Kevin [mailto:[email protected]]
Sent: Thursday, February 12, 2009 11:25 PM
To: [email protected]
Subject: RE: What does Insert method return
I believe that your parameterMap (or parameterClass) object as defined in the
parameterClass attribute of the <insert> statement in your sqlMap file, will
have the attribute that matched the keyProperty set, so when the insert()
method returns, in your example below, newRecord will have the matching
attribute set by the iBatis call. If "newRecord" has an attribute called
generatedSequenceId_0, and you specify this as your keyProperty value (i.e.
<selectKey resultClass="int" keyProperty="generatedSequenceId_0">), then the
setter is called on the parameterClass when the keyProperty is derived.
Does this answer your question?
-Kevin
-----Original Message-----
From: Rahul Saluja [mailto:[email protected]]
Sent: February 12, 2009 11:23 AM
To: [email protected]
Subject: RE: What does Insert method return
Hi Sundar and Larry,
Really appreciate you taking out time and replying but my question still stands
unanswered .
My question is the select key returns the generated sequence number in case of
insert (that I know) ,so if I use the parameters class field as value to
keyProperty attribute will that be set to in my parameters class's particular
field i.e in my case generatedSequenceId_0 or will it be returned simply as an
Integer object so in my code do I need to first call the getter method for
generatedSequenceId_0 and then call type cast back to Integer Object and then
call.intvalue on that object or what....... All I want is generated sequence to
be available in java code.
sqlMap.startTransaction();
Object o = sqlMap.insert(a, newRecord);
Myobject mo = (MyObject)0;
Mo.getgeneratedSequenceId_0().intvalue();
sqlMap.startBatch();
Plsss help me I am confused.
Eagerly Looking forward to response.
Regards
Rahul Saluja
________________________________
From: Sundar Sankar [mailto:[email protected]]
Sent: Thursday, February 12, 2009 9:42 PM
To: [email protected]
Subject: Re: What does Insert method return
Hi Rahul
check this website out
http://ibatis.apache.org/docs/java/user/com/ibatis/sqlmap/client/SqlMapClient.html.
It seems to say that it will return the number of rows inserted.
Though I understand you have no test bed but I would still suggest you some how
test it with a rollback enabled and see if the actual object or any other
variety results do come back. I am not sure if you have spring in you app, But
if you do, enabling a unit test is a piece of cake in Spring 2.5 +
-Sundar
On Thu, Feb 12, 2009 at 8:25 AM, Rahul Saluja
<[email protected]<mailto:[email protected]>> wrote:
Hello Everyone,
Can anyone tell me what exactly does sqlmapclient.insert method return I know
it returns an object but does it returns the object of selectkey means say in
following example
<selectKey keyProperty="generatedSequenceId_0" resultClass="int">
SELECT currval('MSCPerfCntrTrunk_seq')
</selectKey>
Does it return an Integer Object containing an sequence value generated by my
insert statement
or
does it return the actual Object which was just inserted with the
generatedSequenceId_0 field assigned the generated sequence number.
Eagerly Looking forward to your response.
Regards
Rahul Saluja
The information contained in this e-mail is private & confidential and may also
be legally privileged. If you are not the intended recipient, please notify us,
preferably by e-mail, and do not read, copy or disclose the contents of this
message to anyone.
The information contained in this e-mail is private & confidential and may also
be legally privileged. If you are not the intended recipient, please notify us,
preferably by e-mail, and do not read, copy or disclose the contents of this
message to anyone.
The information contained in this e-mail is private & confidential and may also
be legally privileged. If you are not the intended recipient, please notify us,
preferably by e-mail, and do not read, copy or disclose the contents of this
message to anyone.