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

Comments

Projects
None yet
3 participants
@MikeMitterer

MikeMitterer commented Jan 23, 2017

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

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Jan 23, 2017

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!

Member

harawata commented Jan 23, 2017

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

This comment has been minimized.

Show comment
Hide comment
@kazuki43zoo

kazuki43zoo Feb 14, 2017

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 ?

Member

kazuki43zoo commented Feb 14, 2017

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

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Jun 7, 2017

Member

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

Member

harawata commented Jun 7, 2017

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

@harawata

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Jun 8, 2017

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Jun 13, 2017

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.

Member

harawata commented Jun 13, 2017

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 from ExecutorException: No setter found for the keyProperty ... - problem with 3.4.2 to ExecutorException: No setter found for the keyProperty 'id' Aug 13, 2017

@harawata

This comment has been minimized.

Show comment
Hide comment
@harawata

harawata Aug 13, 2017

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!

Member

harawata commented Aug 13, 2017

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 harawata closed this Aug 13, 2017

harawata added a commit to harawata/mybatis-3 that referenced this issue Feb 28, 2018

Unset default value of keyProperty.
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

Merge pull request #1250 from harawata/resurrect-782
Throw exception when keyProperty is not found.
Originally developed by @kazuki43zoo in #782 . But reverted in #1073 to workaround #902 .

h3adache added a commit that referenced this issue May 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment