diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java index 9720ce3ab9..a834d337d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java @@ -529,7 +529,7 @@ public class Oracle8iDialect extends Dialect { @Override public String generateTemporaryTableName(String baseTableName) { final String name = super.generateTemporaryTableName( baseTableName ); - return name.length() > 30 ? name.substring( 1, 30 ) : name; + return name.length() > 30 ? name.substring( 0, 30 ) : name; } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java new file mode 100644 index 0000000000..f71efd9842 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java @@ -0,0 +1,53 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2014, 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.dialect; + +import org.junit.Test; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; + +import static org.junit.Assert.assertEquals; + +public class Oracle8iDialectTestCase extends BaseUnitTestCase { + + @Test + @TestForIssue(jiraKey = "HHH-9290") + public void testTemporaryTableNameTruncation() throws Exception { + String temporaryTableName = new Oracle8iDialect().generateTemporaryTableName( + "TABLE_NAME_THAT_EXCEEDS_30_CHARACTERS" + ); + + assertEquals( + "Temporary table names should be truncated to 30 characters", + 30, + temporaryTableName.length() + ); + assertEquals( + "Temporary table names should start with HT_", + "HT_TABLE_NAME_THAT_EXCEEDS_30_", + temporaryTableName + ); + } +} \ No newline at end of file