HHH-9983 - Fix Error saving entity with identity id on Oracle 12c

This commit is contained in:
Andrea Boriero 2015-09-03 23:43:29 +01:00
parent 1f3048e572
commit 33458ab6f8
3 changed files with 56 additions and 0 deletions

View File

@ -7,6 +7,8 @@
package org.hibernate.dialect;
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.SQL2008StandardLimitHandler;
@ -31,4 +33,9 @@ public class Oracle12cDialect extends Oracle10gDialect {
public LimitHandler getLimitHandler() {
return SQL2008StandardLimitHandler.INSTANCE;
}
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new Oracle12cIdentityColumnSupport();
}
}

View File

@ -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 );
}
}

View File

@ -6,6 +6,9 @@
*/
package org.hibernate.dialect.identity;
import org.hibernate.dialect.Dialect;
import org.hibernate.id.PostInsertIdentityPersister;
/**
* @author Andrea Boriero
*/
@ -24,4 +27,10 @@ public class Oracle12cIdentityColumnSupport extends IdentityColumnSupportImpl {
public String getIdentityColumnString(int type) {
return "generated as identity";
}
@Override
public GetGeneratedKeysDelegate buildGetGeneratedKeysDelegate(
PostInsertIdentityPersister persister, Dialect dialect) {
return new Oracle12cGetGeneratedKeysDelegate( persister, dialect );
}
}