ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Volkmann <m...@ociweb.com>
Subject Re: SQL Server JDBC drivers
Date Tue, 27 Mar 2007 18:02:58 GMT
On Mar 27, 2007, at 12:49 PM, Niels Beekman wrote:
> Try “SELECT SCOPE_IDENTITY() AS ID”, you specified  
> keyProperty=”id”, so iBATIS looks for a column “id” which is not  
> there, hence the null.
I do have a column named "id" which is my primary key.
I tried what you suggested, verified that it put that SQL in my  
generated SqlMap.xml file, and I still get null back.
> Niels
>
> From: Mark Volkmann [mailto:mark@ociweb.com]
> Sent: dinsdag 27 maart 2007 18:45
> To: user-java@ibatis.apache.org
> Subject: Re: SQL Server JDBC drivers
>
>
>
> On Mar 22, 2007, at 1:40 AM, Abdullah Kauchali wrote:
>
>
>
>
> Avoid using @@Identity and instead use Scope_Identity().
>
>
>
> Here is a blogg that summarises the point:
>
>
>
> http://cf-bill.blogspot.com/2005/08/identity-scopeidentity- 
> identcurrent.html
>
>
>
> Has links to MSDN for details.
>
>
>
> I've got my code working now, but only with @@IDENTITY, not with  
> SCOPE_IDENTITY().
>
>
>
> If I have this inside a table element in my AbatorConfig.xml ...
>
>
>
>    <generatedKey column="id" sqlStatement="SqlServer"  
> identity="true"/>
>
>
>
> then it generates this in my mapping file ...
>
>
>
>   <insert id="abatorgenerated_insert"  
> parameterClass="com.savealot.xademo.model.Address" >
>
>     insert into GWT_Test..address (street, city, state, zip)
>
>     values (#street:VARCHAR#, #city:VARCHAR#, #state:VARCHAR#,  
> #zip:INTEGER#)
>
>     <selectKey resultClass="java.lang.Integer" keyProperty="id" >
>
>       SELECT SCOPE_IDENTITY()
>
>     </selectKey>
>
>   </insert>
>
>
>
> and when I run I get ...
>
>
>
> java.lang.NullPointerException
>
>             com.savealot.client.SpringDAOClient.addAddress 
> (SpringDAOClient.java:56)
>
>             com.savealot.client.SpringDAOClient.loadDB 
> (SpringDAOClient.java:84)
>
>
>
> However, if change the generateKey element to this ...
>
>
>
>    <generatedKey column="id" sqlStatement="SELECT @@IDENTITY AS ID"  
> identity="true"/>
>
>
>
> then it generates this in my mapping file ...
>
>
>
>   <insert id="abatorgenerated_insert"  
> parameterClass="com.savealot.xademo.model.Address" >
>
>     insert into GWT_Test..address (street, city, state, zip)
>
>     values (#street:VARCHAR#, #city:VARCHAR#, #state:VARCHAR#,  
> #zip:INTEGER#)
>
>     <selectKey resultClass="java.lang.Integer" keyProperty="id" >
>
>       SELECT @@IDENTITY AS ID
>
>     </selectKey>
>
>   </insert>
>
>
>
> where the only difference is the SELECT statement, and everything  
> works fine.
>
>
>
> Any idea why I can't get SCOPE_IDENTITY() to work? Perhaps  
> something I'm doing wrong defining the table?
>
>
>
>> -----Original Message-----
>>
>> From: Niels Beekman [mailto:n.beekman@wis.nl]
>>
>> Sent: Wednesday, March 21, 2007 10:19 PM
>>
>> To: user-java@ibatis.apache.org
>>
>> Subject: FW: SQL Server JDBC drivers
>>
>>
>>
>> And for the archives...
>>
>>
>>
>> -----Original Message-----
>>
>> From: Niels Beekman
>>
>> Sent: woensdag 21 maart 2007 20:33
>>
>> To: 'Mark Volkmann'
>>
>> Subject: RE: SQL Server JDBC drivers
>>
>>
>>
>> Sure:
>>
>>
>>
>> <insert id="Example_insert" parameterClass="Example">
>>
>>   INSERT INTO example (example_column)
>>
>>   VALUES (#exampleColumn#)
>>
>>   <selectKey keyProperty="exampleId" resultClass="int">
>>
>>     SELECT @@IDENTITY AS ID
>>
>>   </selectKey>
>>
>> </insert>
>>
>>
>>
>> iBATIS will then populate the property "exampleId" with the value of
>>
>> the
>>
>> auto-incremented column.
>>
>>
>>
>> HTH,
>>
>>
>>
>> Niels
>>
>>
>>
>> -----Original Message-----
>>
>> From: Mark Volkmann [mailto:mark@ociweb.com]
>>
>> Sent: woensdag 21 maart 2007 20:28
>>
>> To: Niels Beekman; Graeme J Sweeney; Rose, Greg
>>
>> Cc: Dan Berghoff
>>
>> Subject: Re: SQL Server JDBC drivers
>>
>>
>>
>> Thanks to the three of you for replying!
>>
>>
>>
>> We're having trouble getting iBATIS to work with tables that have an
>>
>> integer primary key that is auto-incremented. If you have done that,
>>
>> can you send me the relevant snippet of XML from one of your {name}
>>
>> _SqlMap.xml files?
>>
>>
>>
>> Thanks!
>>
>>
>>
>> On Mar 21, 2007, at 11:36 AM, Niels Beekman wrote:
>>
>>
>>> Hi,
>>>
>>>
>>>
>>> We use jTDS (http://jtds.sf.net) for several years now, it has
>>>
>>> excellent
>>>
>>> performance and any bugs (which are very rare) are dealt with
>>>
>>> promptly.
>>>
>>>
>>>
>>> Niels
>>>
>>>
>>>
>>> -----Original Message-----
>>>
>>> From: Mark Volkmann [mailto:mark@ociweb.com]
>>>
>>> Sent: woensdag 21 maart 2007 17:28
>>>
>>> To: user-java@ibatis.apache.org
>>>
>>> Subject: SQL Server JDBC drivers
>>>
>>>
>>>
>>> If you have successfully used iBATIS with SQL Server, can you  
>>> tell me
>>>
>>> what JDBC driver(s) have worked for you?
>
>
>
>
>


Mime
View raw message