diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java index 3a1503a08d..88a17a8a55 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java @@ -77,9 +77,11 @@ public final class IdentifierGeneratorHelper { * Get the generated identifier when using identity columns * * @param rs The result set from which to extract the the generated identity. - * @param identifier + * @param identifier The name of the identifier column * @param type The expected type mapping for the identity value. + * * @return The generated identity value + * * @throws SQLException Can be thrown while accessing the result set * @throws HibernateException Indicates a problem reading back a generated identity value. */ @@ -97,9 +99,11 @@ public final class IdentifierGeneratorHelper { * and wrp it in the appropriate Java numeric type. * * @param rs The result set from which to extract the value. - * @param identifier + * @param identifier The name of the identifier column * @param type The expected type of the value. + * * @return The extracted value. + * * @throws SQLException Indicates problems access the result set * @throws IdentifierGenerationException Indicates an unknown type. */ @@ -139,7 +143,8 @@ public final class IdentifierGeneratorHelper { "unrecognized id type : " + type.getName() + " -> " + clazz.getName() ); } - } else { + } + else { if ( clazz == Long.class ) { return rs.getLong(identifier); } diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java index be3afc4d84..0c90f1604e 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java @@ -92,14 +92,14 @@ public class IdentityGenerator extends AbstractPostInsertGenerator { .prepareStatement( insertSQL, PreparedStatement.RETURN_GENERATED_KEYS ); } - public Serializable executeAndExtract(PreparedStatement insert, String identifier) throws SQLException { + public Serializable executeAndExtract(PreparedStatement insert) throws SQLException { insert.executeUpdate(); ResultSet rs = null; try { rs = insert.getGeneratedKeys(); return IdentifierGeneratorHelper.getGeneratedIdentity( rs, - identifier, + persister.getIdentifierColumnNames()[0], persister.getIdentifierType() ); } @@ -140,7 +140,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator { .prepareStatement( insertSQL, PreparedStatement.NO_GENERATED_KEYS ); } - public Serializable executeAndExtract(PreparedStatement insert, String identifier) throws SQLException { + public Serializable executeAndExtract(PreparedStatement insert) throws SQLException { if ( !insert.execute() ) { while ( !insert.getMoreResults() && insert.getUpdateCount() != -1 ) { // do nothing until we hit the rsult set containing the generated id @@ -148,7 +148,11 @@ public class IdentityGenerator extends AbstractPostInsertGenerator { } ResultSet rs = insert.getResultSet(); try { - return IdentifierGeneratorHelper.getGeneratedIdentity( rs, identifier, persister.getIdentifierType() ); + return IdentifierGeneratorHelper.getGeneratedIdentity( + rs, + persister.getIdentifierColumnNames()[0], + persister.getIdentifierType() + ); } finally { rs.close(); diff --git a/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentityPersister.java b/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentityPersister.java index 85d6149a7a..24880a269a 100755 --- a/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentityPersister.java @@ -50,6 +50,8 @@ public interface PostInsertIdentityPersister extends EntityPersister { */ public String getIdentitySelectString(); + public String[] getIdentifierColumnNames(); + /** * The names of the primary key columns in the root table. * diff --git a/hibernate-core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java index af38b1ccfd..c7e1427f3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java @@ -107,11 +107,12 @@ public class SequenceIdentityGenerator } @Override - protected Serializable executeAndExtract(PreparedStatement insert, String identifier) throws SQLException { + protected Serializable executeAndExtract(PreparedStatement insert) throws SQLException { insert.executeUpdate(); return IdentifierGeneratorHelper.getGeneratedIdentity( insert.getGeneratedKeys(), - identifier, getPersister().getIdentifierType() + getPersister().getIdentifierColumnNames()[0], + getPersister().getIdentifierType() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractReturningDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractReturningDelegate.java index 9a9288053e..1f934024c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractReturningDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractReturningDelegate.java @@ -46,13 +46,16 @@ public abstract class AbstractReturningDelegate implements InsertGeneratedIdenti this.persister = persister; } - public final Serializable performInsert(String insertSQL, String identifiers, SessionImplementor session, Binder binder) { + public final Serializable performInsert( + String insertSQL, + SessionImplementor session, + Binder binder) { try { // prepare and execute the insert PreparedStatement insert = prepare( insertSQL, session ); try { binder.bindValues( insert ); - return executeAndExtract( insert, identifiers ); + return executeAndExtract( insert ); } finally { releaseStatement( insert, session ); @@ -73,7 +76,7 @@ public abstract class AbstractReturningDelegate implements InsertGeneratedIdenti protected abstract PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException; - protected abstract Serializable executeAndExtract(PreparedStatement insert, String identifiers) throws SQLException; + protected abstract Serializable executeAndExtract(PreparedStatement insert) throws SQLException; protected void releaseStatement(PreparedStatement insert, SessionImplementor session) throws SQLException { insert.close(); diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java index 100208fc7a..aaf3dc9bec 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java @@ -46,7 +46,10 @@ public abstract class AbstractSelectingDelegate implements InsertGeneratedIdenti this.persister = persister; } - public final Serializable performInsert(String insertSQL, String identifier, SessionImplementor session, Binder binder) { + public final Serializable performInsert( + String insertSQL, + SessionImplementor session, + Binder binder) { try { // prepare and execute the insert PreparedStatement insert = session.getTransactionCoordinator() diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java index 4c92517c4d..c0a7cfd48a 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/InsertGeneratedIdentifierDelegate.java @@ -50,12 +50,13 @@ public interface InsertGeneratedIdentifierDelegate { * Perform the indicated insert SQL statement and determine the identifier value * generated. * + * * @param insertSQL The INSERT statement string - * @param identifiers * @param session The session in which we are operating * @param binder The param binder + * * @return The generated identifier value. */ - public Serializable performInsert(String insertSQL, String identifiers, SessionImplementor session, Binder binder); + public Serializable performInsert(String insertSQL, SessionImplementor session, Binder binder); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 76aa09493c..1891b426d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -2756,9 +2756,7 @@ public abstract class AbstractEntityPersister } }; - String[] identifiers = getIdentifierColumnNames(); - - return identityDelegate.performInsert( sql, identifiers[0], session, binder ); + return identityDelegate.performInsert( sql, session, binder ); } public String getIdentitySelectString() { diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/InheritingEntity.java b/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/InheritingEntity.java index 68b251556a..cea1f1a161 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/InheritingEntity.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/InheritingEntity.java @@ -1,3 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.inheritancediscriminator; import javax.persistence.Column; @@ -5,7 +28,7 @@ import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; /** - * Created by Pawel Stawicki on 8/17/11 11:01 PM + * @author Pawel Stawicki */ @Entity @DiscriminatorValue("1") diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/ParentEntity.java b/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/ParentEntity.java index 4d2d96427e..d65bdd21b8 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/ParentEntity.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/ParentEntity.java @@ -1,3 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.inheritancediscriminator; import javax.persistence.Column; @@ -12,9 +35,8 @@ import static javax.persistence.GenerationType.IDENTITY; import static javax.persistence.InheritanceType.SINGLE_TABLE; /** - * Created by Pawel Stawicki on 8/17/11 11:01 PM + * @author Pawel Stawicki */ - @Entity @Inheritance(strategy = SINGLE_TABLE) @DiscriminatorColumn(name = "CLASS_ID", discriminatorType = INTEGER) diff --git a/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/PersistChildEntitiesWithDiscriminatorTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/PersistChildEntitiesWithDiscriminatorTest.java index eaaf5b9bd6..ad432f9fe3 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/PersistChildEntitiesWithDiscriminatorTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/inheritancediscriminator/PersistChildEntitiesWithDiscriminatorTest.java @@ -1,9 +1,39 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2012, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ package org.hibernate.test.inheritancediscriminator; import org.hibernate.Session; +import org.hibernate.dialect.PostgreSQLDialect; + +import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; +/** + * @author Pawel Stawicki + */ +@RequiresDialect( value = PostgreSQLDialect.class, jiraKey = "HHH-6580" ) public class PersistChildEntitiesWithDiscriminatorTest extends BaseCoreFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() {