Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error getting generated key or setting result to parameter object. Cause: java.sql.SQLFeatureNotSupportedException: not implemented by SQLite JDBC driver #1028

Closed
aca00 opened this issue Dec 2, 2023 · 1 comment
Labels

Comments

@aca00
Copy link

aca00 commented Dec 2, 2023

Describe the bug
I was trying to get the ID of an inserted item using Mybatis. In the XML file, when I use keyProperty parameter, I get org.springframework.dao.InvalidDataAccessApiUsageException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLFeatureNotSupportedException: not implemented by SQLite JDBC driver; not implemented by SQLite JDBC driver error.

To Reproduce
Playlist Entity is defined like this;

@Data
@AllArgsConstructor
public class Playlist {
    private long id;
    private String playlistName;
    private String playlistUrl;
}

PlaylistRepository.java

@org.apache.ibatis.annotations.Mapper
public interface PlaylistRepository {
    Long save(Playlist task);
}

PlaylistRepository.XML

    <insert id="save" parameterType="com.prod.transponder.entity.Playlist" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
        insert into playlist (playlist_name, source_url) values
        (#{playlistName}, #{playlistUrl})
    </insert>
// No error if I omit the parameter `keyProperty`

The playlist table definition

drop table if exists playlist;
create table playlist(
    id integer,
    source_url text,
    playlist_name text,
    primary key(id)
);

Relevant dependencies;

<dependency>
	<groupId>org.xerial</groupId>
	<artifactId>sqlite-jdbc</artifactId>
	<version>3.44.1.0</version>
</dependency>
<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>3.0.3</version>
</dependency>

Expected behavior
Add new item in playlist table with key auto-generated and the key being set to the object passed to the save method like this or this

Logs

Connected to the target VM, address: '127.0.0.1:57121', transport: 'socket'
23:00:32.194 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.prod.transponder.repository.PlaylstRepositoryTest]: PlaylstRepositoryTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
23:00:32.338 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.prod.transponder.TransponderApplication for test class com.prod.transponder.repository.PlaylstRepositoryTest
2023-12-02T23:00:32.877+05:30  INFO 31209 --- [           main] c.p.t.r.PlaylstRepositoryTest          : Starting PlaylstRepositoryTest using Java 17.0.8 with PID 31209 (started by aca in /home/aca/ideaProjects/satellite/transponder)
2023-12-02T23:00:32.879+05:30  INFO 31209 --- [           main] c.p.t.r.PlaylstRepositoryTest          : No active profile set, falling back to 1 default profile: "default"
2023-12-02T23:00:34.315+05:30  INFO 31209 --- [           main] c.p.t.r.PlaylstRepositoryTest          : Started PlaylstRepositoryTest in 1.755 seconds (process running for 3.198)
2023-12-02T23:00:34.331+05:30  INFO 31209 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-12-02T23:00:34.466+05:30  INFO 31209 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.sqlite.jdbc4.JDBC4Connection@79afa369
2023-12-02T23:00:34.478+05:30  INFO 31209 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
[]
2023-12-02T23:00:34.518+05:30  INFO 31209 --- [           main] c.p.transponder.TransponderApplication   : jdbc:sqlite:/home/aca/ideaProjects/satellite/transponder/src/main/resources/static/test.db
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

org.springframework.dao.InvalidDataAccessApiUsageException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLFeatureNotSupportedException: not implemented by SQLite JDBC driver
; not implemented by SQLite JDBC driver

	at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:106)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:107)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:116)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439)
	at jdk.proxy2/jdk.proxy2.$Proxy62.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:272)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:141)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
	at jdk.proxy2/jdk.proxy2.$Proxy73.save(Unknown Source)
	at com.prod.transponder.repository.PlaylstRepositoryTest.should_saveTaskItem_when_calledSaveMethod(PlaylstRepositoryTest.java:24)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: java.sql.SQLFeatureNotSupportedException: not implemented by SQLite JDBC driver
	at org.sqlite.jdbc3.JDBC3PreparedStatement.unsupported(JDBC3PreparedStatement.java:448)
	at org.sqlite.jdbc3.JDBC3Statement.getGeneratedKeys(JDBC3Statement.java:361)
	at com.zaxxer.hikari.pool.ProxyStatement.getGeneratedKeys(ProxyStatement.java:229)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.getGeneratedKeys(HikariProxyPreparedStatement.java)
	at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processBatch(Jdbc3KeyGenerator.java:79)
	at org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:71)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:52)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:75)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425)
	... 10 more

2023-12-02T23:00:35.339+05:30  INFO 31209 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-12-02T23:00:35.342+05:30  INFO 31209 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
Disconnected from the target VM, address: '127.0.0.1:57121', transport: 'socket'

Process finished with exit code 255

Environment (please complete the following information):

  • OS: Ubuntu 23.10
  • CPU architecture: x86_64
  • sqlite-jdbc version: 3.44.1.0
  • mybatis version: 3.0.3
  • Java 17
@aca00 aca00 added the triage label Dec 2, 2023
@gotson
Copy link
Collaborator

gotson commented Dec 3, 2023

Dupe of #963?

@aca00 aca00 closed this as completed Dec 3, 2023
Repository owner locked as resolved and limited conversation to collaborators Feb 9, 2024
Repository owner deleted a comment from prrvchr Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants