HHH-9983 - Fix Error saving entity with identity id on Oracle 12c
This commit is contained in:
parent
1f3048e572
commit
33458ab6f8
|
@ -7,6 +7,8 @@
|
||||||
package org.hibernate.dialect;
|
package org.hibernate.dialect;
|
||||||
|
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
|
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||||
|
import org.hibernate.dialect.identity.Oracle12cIdentityColumnSupport;
|
||||||
import org.hibernate.dialect.pagination.LimitHandler;
|
import org.hibernate.dialect.pagination.LimitHandler;
|
||||||
import org.hibernate.dialect.pagination.SQL2008StandardLimitHandler;
|
import org.hibernate.dialect.pagination.SQL2008StandardLimitHandler;
|
||||||
|
|
||||||
|
@ -31,4 +33,9 @@ public class Oracle12cDialect extends Oracle10gDialect {
|
||||||
public LimitHandler getLimitHandler() {
|
public LimitHandler getLimitHandler() {
|
||||||
return SQL2008StandardLimitHandler.INSTANCE;
|
return SQL2008StandardLimitHandler.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IdentityColumnSupport getIdentityColumnSupport() {
|
||||||
|
return new Oracle12cIdentityColumnSupport();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.dialect.identity;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.dialect.identity.GetGeneratedKeysDelegate;
|
||||||
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
import org.hibernate.id.PostInsertIdentityPersister;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrea Boriero
|
||||||
|
*/
|
||||||
|
public class Oracle12cGetGeneratedKeysDelegate extends GetGeneratedKeysDelegate {
|
||||||
|
private String[] keyColumns;
|
||||||
|
|
||||||
|
public Oracle12cGetGeneratedKeysDelegate(PostInsertIdentityPersister persister, Dialect dialect) {
|
||||||
|
super( persister, dialect );
|
||||||
|
this.keyColumns = getPersister().getRootTableKeyColumnNames();
|
||||||
|
if ( keyColumns.length > 1 ) {
|
||||||
|
throw new HibernateException( "Identity generator cannot be used with multi-column keys" );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException {
|
||||||
|
return session
|
||||||
|
.getJdbcCoordinator()
|
||||||
|
.getStatementPreparer()
|
||||||
|
.prepareStatement( insertSQL, keyColumns );
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,9 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.dialect.identity;
|
package org.hibernate.dialect.identity;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.id.PostInsertIdentityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Boriero
|
* @author Andrea Boriero
|
||||||
*/
|
*/
|
||||||
|
@ -24,4 +27,10 @@ public class Oracle12cIdentityColumnSupport extends IdentityColumnSupportImpl {
|
||||||
public String getIdentityColumnString(int type) {
|
public String getIdentityColumnString(int type) {
|
||||||
return "generated as identity";
|
return "generated as identity";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(
|
||||||
|
PostInsertIdentityPersister persister, Dialect dialect) {
|
||||||
|
return new Oracle12cGetGeneratedKeysDelegate( persister, dialect );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue