Hi Maduranga, That is not a correct approach in doing that. If you separate those two calls between two data service calls, you will not be in the same session for it to return the last inserted id, for example, another insert could have been done between the two calls and so on. So you've to either wrap your put and getting auto generated id functionality into a stored procedure and call that using the data service, or else, you can simply use the "returnAutoGeneratedKey" feature [1] we have in data services to do the exact thing.
[1] http://docs.wso2.org/display/DSS311/Returning+Generated+Keys Cheers, Anjana. On Mon, Feb 10, 2014 at 4:51 PM, Maduranga Siriwardena <[email protected]>wrote: > Hi all, > > I'm using a data service and I want to get the last inserted id of a auto > incremented column from the database. After executing the insert query, I > call a get resource that execute the following query in the data service > server. > > <query id="get_last_inserted_id" useConfig="default"> > <sql>SELECT LAST_INSERT_ID() AS LAST_INSERTED_ID</sql> > <result element="WSO2_QAP_FEATURECollection" > rowName="WSO2_QAP_FEATURE"> > <element column="LAST_INSERTED_ID" name="LAST_INSERTED_ID" > xsdType="xs:integer"/> > </result> > </query> > > Sometimes I get the correct id and sometimes I get "0" as the last > inserted id. Can someone help me to resolve this problem or any other > workaround to get the last inserted id. > > Regards > > _______________________________________________ > Dev mailing list > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- *Anjana Fernando* Technical Lead WSO2 Inc. | http://wso2.com lean . enterprise . middleware
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
