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

1.5.3不能正常使用mysql的自增主键 报错 Generated keys not requested. #360

Closed
cyao2q opened this issue Sep 6, 2017 · 9 comments

Comments

@cyao2q
Copy link

cyao2q commented Sep 6, 2017

Please answer these questions before submitting your issue. Thanks!

Which version of Sharding-Jdbc do you using?

1.5.3

Expected behavior

1.5.2可以正常使用mysql的自增主键

Actual behavior

Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().

Steps to reproduce the behavior

CREATE TABLE sequence (
id int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

public Long getSequence() {
Sequence sequence = new Sequence();
testDao.getSequence(sequence);
return sequence.getId();
}

insert into sequence() values()

Please provide the reproduce example codes (such as github link) if possible.

@terrymanu
Copy link
Member

terrymanu commented Sep 6, 2017

信息不足,请提供可供重现的代码。
或者提供全部的sql.show日志、ShardingRule配置、SQL以及调用SQL的代码片段

@fugaoyang
Copy link

fugaoyang commented Sep 7, 2017

我同样遇到的是 :在插入非分片表时,报了这样的错:
Caused by: java.sql.SQLException: Generated keys not requested.
You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
at com.mysql.jdbc.StatementImpl.getGeneratedKeys(StatementImpl.java:1971)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.getGeneratedKeys(NewProxyPreparedStatement.java:1749)
at com.dangdang.ddframe.rdb.sharding.jdbc.core.statement.ShardingPreparedStatement.getGeneratedKeys(ShardingPreparedStatement.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

@terrymanu
Copy link
Member

请一次性将所需信息提供完善吧。这样沟通成本太高,一天就这么过去了。

@fugaoyang
Copy link

fugaoyang commented Sep 7, 2017

我用的spring mybatis ,插入的mapper.xml配置如下:

insert into CTS_TRADE_REQUEST
(TRADE_REQ_NO, ORDER_NO, OUTER_TRANS_ID,
ACK_OUTER_TRANS_ID)---

sharding rule配置如下:
<rdb:data-source id="shardingDataSource">
<rdb:sharding-rule data-sources="dataSource.cts" default-data-source="dataSource.cts"
key-generator-class="com.biz.sharding.IncrementKeyGenerator">
rdb:table-rules
<rdb:table-rule logic-table="CTS_VACCO_PAYMENT_DETAIL"
actual-tables="CTS_VACCO_PAYMENT_DETAIL_0,CTS_VACCO_PAYMENT_DETAIL_1,CTS_VACCO_PAYMENT_DETAIL_2,CTS_VACCO_PAYMENT_DETAIL_3"
table-strategy="paymentDetailTableStrategy" >
<rdb:generate-key-column column-name="id"/>
</rdb:table-rule>
</rdb:table-rules>
rdb:binding-table-rules
<rdb:binding-table-rule logic-tables="CTS_VACCO_PAYMENT_DETAIL"/>
</rdb:binding-table-rules>
<rdb:default-table-strategy sharding-columns="none"
algorithm-class="com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm"/>
</rdb:sharding-rule>
rdb:props
true
true
</rdb:props>
</rdb:data-source>

@terrymanu
Copy link
Member

terrymanu commented Sep 7, 2017

请参见之前的信息:
信息不足,请提供可供重现的代码。
或者提供全部的sql.show日志、ShardingRule配置、SQL以及调用SQL的代码片段

请一次性提供所需信息,不然实在不易定位

@cyao2q
Copy link
Author

cyao2q commented Sep 8, 2017

1
2
3
4
5
6
7
8

@terrymanu
Copy link
Member

您这样的代码片段对于我们定位bug并无实质用途。请按照之前交流所写。提供我们需要的信息。
最好提供一个可供重现的demo,并将代码放在guthub上,将连接交给我们。
时间精力有限,请大家各司其职。
我们负责修改bug,请您负责将bug以最低的理解成本重现在我们面前,谢谢合作。

@terrymanu
Copy link
Member

由于您没提供可重现的代码,并自行关闭了issue。
因此这个issue我算为invalid了

@terrymanu
Copy link
Member

dup #370

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

No branches or pull requests

3 participants