Skip to content

Using @Update or @Insert with PostgreSQL's RETURNING to get the updated object #1293

@CatalinaMoisuc

Description

@CatalinaMoisuc

Would be really nice if it would be possible to use @Update, @Insert and also to map the returned object, using PostgreSQL's RETURNING in the statement like:

@Update("UPDATE users " +
  "SET name = #{name} " +
  "WHERE email = #{email} " +
  "RETURNING " +
  "id, " +
  "name, " +
  "email, " +
  "username;”)
User updateUser(@Param("email") String email, @Param(“name”) String name);

Currently this is not working. I get the following error:

org.apache.ibatis.binding.BindingException: Mapper method 'com.example.repository.UserDAO.updateUser’ has an unsupported return type: class com.example.model.User
        at org.apache.ibatis.binding.MapperMethod.rowCountResult(MapperMethod.java:110)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
        ...

I have also tried to map the result like:

@Results({
    @Result(property = "id", column = "id"),
    @Result(property = "name", column = "name"),
    @Result(property = "email", column = "email"),
    @Result(property = "username", column = "username")
  })

but I get the same error.

Note: I am using the following dependency: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:jar:1.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprove a feature or add a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions