前段时间 - 但我遇到了同样的问题 解决方案:首先,您选择的平台必须支持 identityOverrideAllowed。
Platform mySqlPlatform = PlatformFactory.createNewPlatformInstance(mysqlDataSource);
mySqlPlatform.getPlatformInfo().setIdentityOverrideAllowed(true);
您还必须设置 isIdentityOverrideOn 一个如何设置它的示例,您可以在源代码中找到。DDLUtils
org.apache.ddlutils.platform.mssql.MsSqlPlatform...
/**
* Determines whether we need to use identity override mode for the given table.
*
* @param table The table
* @return <code>true</code> if identity override mode is needed
*/
private boolean useIdentityOverrideFor(Table table)
{
return isIdentityOverrideOn() &&
getPlatformInfo().isIdentityOverrideAllowed() &&
(table.getAutoIncrementColumns().length > 0);
}
/**
* {@inheritDoc}
*/
protected void beforeInsert(Connection connection, Table table) throws SQLException
{
if (useIdentityOverrideFor(table))
{
MSSqlBuilder builder = (MSSqlBuilder)getSqlBuilder();
connection.createStatement().execute(builder.getEnableIdentityOverrideSql(table));
}
}
/**
* {@inheritDoc}
*/
protected void afterInsert(Connection connection, Table table) throws SQLException
{
if (useIdentityOverrideFor(table))
{
MSSqlBuilder builder = (MSSqlBuilder)getSqlBuilder();
connection.createStatement().execute(builder.getDisableIdentityOverrideSql(table));
}
}