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

ExecutorException: No setter found for the keyProperty 'id' #902

Closed
MikeMitterer opened this issue Jan 23, 2017 · 6 comments
Closed

ExecutorException: No setter found for the keyProperty 'id' #902

MikeMitterer opened this issue Jan 23, 2017 · 6 comments
Assignees
Labels
Milestone

Comments

@MikeMitterer
Copy link

MyBatis version

3.4.2

Database vendor and version

PostgreSQL 9.6.1

Test case or example project

interface TicketMapper {
    @Options(flushCache = Options.FlushCachePolicy.TRUE, useGeneratedKeys=true) // Set keyProperty as the Java variable name and keyColumn as the column name in the database.
    @Insert("INSERT INTO tickets (apikey, ticket) VALUES (#{apikey},#{ticket})")
    public void insertTicket(final TicketTO ticket) throws RecordAlreadyExists;
   }
-- Tickets für die WebSocket-Anmeldung
CREATE TABLE tickets (
  ID SERIAL PRIMARY KEY,
  crdate    TIMESTAMP DEFAULT LOCALTIMESTAMP,

	-- apikey - ist in diesem Fall ein WebToken
	apikey     VARCHAR(2048)	not null,

  -- das eigentliche Ticket, eine UUID
  ticket    VARCHAR(36)	not null
);
public class TicketTO {

    /** Verweis auf den User */
    private          String   apikey;
    private          String   ticket;
    private DateTime crdate;

    public String getAppID() {  ...  }

    public String getTicket() { ...}

    public void setTicket(final String ticket) { ... }

    public DateTime getCrdate() { ... }

    public void setCrdate(final String crdate) { ... }
}

This line produces to above error:

getSession().getMapper(TicketMapper.class).insertTicket(ticket);

It's true that TicketTO has no "id" but this should be valid!
It works with 3.4.1 but fails with 3.4.2

@harawata
Copy link
Member

Could you please create a demo project including the configuration so that we can reproduce the issue quickly and reliably?
Here are some skeleton projects : https://github.com/harawata/mybatis-issues
Thank you!

@kazuki43zoo
Copy link
Member

Hi @MikeMitterer,

Probably, This issue related with #782.
I think this behavior is work as designed on 3.4.2.
If you want to avoid this behavior, I think useGeneratedKeys should be set to false (or omit this option).

I have a one question. Why did you set useGeneratedKeys=true in this case ?

@harawata
Copy link
Member

harawata commented Jun 7, 2017

#782 explains it, it seems.
Please let us know if you think we are missing something!

@harawata
Copy link
Member

harawata commented Jun 8, 2017

We've got another report on the mailing list.
https://groups.google.com/d/msg/mybatis-user/H940lW-qlXQ/K3MAEL7mCQAJ
#782 might cause problem on PostgreSQL.
Reopen to reevaluate.

@harawata harawata reopened this Jun 8, 2017
harawata added a commit to harawata/mybatis-3 that referenced this issue Jun 13, 2017
@harawata
Copy link
Member

I didn't know that, but there is a default value for keyProperty when using annotation (i.e. @Insert or @Update) and this causes a problem when useGeneratedKeys is enabled in the global config and the database is PostgreSQL [1].
Here are failing tests demonstrating the issue (it uses postgresql-embedded for portability).

Although it is not ideal, we have to revert #782 for now, I think.
The right fix would be to remove the default value for keyProperty, but we must wait for the next major release because it could break backward compatibility.
Does anyone have a better idea?

[1] In PostgreSQL, ResultSetMetaData#getColumnCount() always returns the number of the columns of the inserted/updated even when there is no SERIAL column in the table.

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jul 2, 2017
kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jul 2, 2017
kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jul 2, 2017
kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this issue Jul 2, 2017
harawata added a commit to harawata/mybatis-3 that referenced this issue Aug 9, 2017
harawata added a commit to harawata/mybatis-3 that referenced this issue Aug 12, 2017
harawata added a commit to harawata/mybatis-3 that referenced this issue Aug 12, 2017
harawata added a commit that referenced this issue Aug 13, 2017
@harawata harawata added the bug label Aug 13, 2017
@harawata harawata self-assigned this Aug 13, 2017
@harawata harawata added this to the 3.4.5 milestone Aug 13, 2017
@harawata harawata changed the title ExecutorException: No setter found for the keyProperty ... - problem with 3.4.2 ExecutorException: No setter found for the keyProperty 'id' Aug 13, 2017
@harawata
Copy link
Member

This should be fixed in the latest 3.4.5-SNAPSHOT .
It would be great if you could try it and see if your problem is resolved.
Thanks!

harawata added a commit to harawata/mybatis-3 that referenced this issue Feb 28, 2018
It causes a problem like mybatis#902 and makes it difficult to handle errors in Jdbc3KeyGenerator.
harawata added a commit to harawata/mybatis-3 that referenced this issue Apr 7, 2018
harawata added a commit that referenced this issue Apr 10, 2018
Throw exception when keyProperty is not found.
Originally developed by @kazuki43zoo in #782 . But reverted in #1073 to workaround #902 .
h3adache pushed a commit that referenced this issue May 5, 2018
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
It causes a problem like mybatis#902 and makes it difficult to handle errors in Jdbc3KeyGenerator.
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this issue Oct 19, 2023
Throw exception when keyProperty is not found.
Originally developed by @kazuki43zoo in mybatis#782 . But reverted in mybatis#1073 to workaround mybatis#902 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants