Skip to content

Commit 263a841

Browse files
committed
HHH-7840 org.hibernate.id.IncrementGenerator very slow
1 parent 1f690e7 commit 263a841

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

hibernate-core/src/main/java/org/hibernate/id/IncrementGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
*
5454
* @author Gavin King
5555
* @author Steve Ebersole
56+
* @author Brett Meyer
5657
*/
5758
public class IncrementGenerator implements IdentifierGenerator, Configurable {
5859

@@ -103,7 +104,7 @@ public void configure(Type type, Properties params, Dialect dialect) throws Mapp
103104
for ( int i=0; i < tables.length; i++ ) {
104105
final String tableName = dialect.quote( normalizer.normalizeIdentifierQuoting( tables[i] ) );
105106
if ( tables.length > 1 ) {
106-
buf.append( "select " ).append( column ).append( " from " );
107+
buf.append( "select max(" ).append( column ).append( ") as mx from " );
107108
}
108109
buf.append( Table.qualify( catalog, schema, tableName ) );
109110
if ( i < tables.length-1 ) {
@@ -112,7 +113,7 @@ public void configure(Type type, Properties params, Dialect dialect) throws Mapp
112113
}
113114
if ( tables.length > 1 ) {
114115
buf.insert( 0, "( " ).append( " ) ids_" );
115-
column = "ids_." + column;
116+
column = "ids_.mx";
116117
}
117118

118119
sql = "select max(" + column + ") from " + buf.toString();

0 commit comments

Comments
 (0)