jdbc - getGeneratedKeys feature is not supported by this database -


i running sql anywhere 16.0 , trying hand @ spring jdbc templates. need simple: insert row table, auto-generated id value.

public int log() {     simplejdbcinsert insertactor =              new simplejdbcinsert(ds)             .withtablename("dba.requests")             .usinggeneratedkeycolumns("request_id");      map<string, object> parameters = new hashmap<string, object>();     parameters.put("user_id", userid);     parameters.put("data_type_id", getproductsku());     parameters.put("price", price);     // ...more parameters      number requestidnumber = insertactor.executeandreturnkey(parameters);     return requestidnumber.intvalue(); } 

but spring repeatedly gives me error

org.springframework.dao.invaliddataaccessresourceusageexception:    getgeneratedkeys feature not supported database 

the driver using should support jdbc 4.0 (the library dbjdbc16.dll , in path, , sajdbc4.jar in tomcat lib directory). relevant database connection info tomcat is

    <resource auth="container" description="pooled connection web database"      driverclassname="sybase.jdbc4.sqlanywhere.idriver"      maxactive="30" maxidle="5" maxwait="10000" name="jdbc/web"      removeabandoned="true"      removeabandonedtimeout="60"      type="javax.sql.datasource"      url="jdbc:sqlanywhere:server=web;uid=xxx;password=xxx;port=xxxx;links=tcpip(port=xxxx)"/> 

and spring application context datasource is

<jee:jndi-lookup id="dbdatasource" jndi-name="jdbc/web"             expected-type="javax.sql.datasource" />   

so question is, there way configure things better type of statement works? or if database not support on fundamental level, there non-ugly alternative me insert values , generated id.

update: appears database driver not support feature. suggestions here , elsewhere insert select following. problem, of course, if user inserts table between 2 statements wrong value , quite bad in case.

my workaround right use class-level lock on relevant dao, , select based on several columns (not identity) can 99.9% sure i'm getting same row back. enough work. said, i'd prefer have transactional way of locking table. don't think marking function @transactional work this, right, delays commit until statements successful?

i'm no jdbc expert @ can't answer question directly, can tell sql anywhere server have ability. if jdbc stuff isn't working, use @@identity variable. fetching select @@identity return auto-generated value last statement.

disclaimer: work sap in sql anywhere engineering.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -