IncrementGenerator broken for tables with blanks in their names after TODO-173


The following change to

revision 1.11
date: 2005/04/26 06:37:53; author: oneovthafew; state: Exp; lines: +24 -5
TODO-173, increment for union-subclass
SQL logging from id generators
seems to have broken this generator when used on tables with blanks in their names.

This update tries to allow access to a comma-separated list of tables to identify the currently max-value of an id column.

I have a with the following mapping (in extract):


<class name="dk.statsbiblioteket.navision.integration.Transaction" table="`REGNSKAB$SB Transaktioner`" dynamic-update="true">
<id name="lbNummer">
<column name="`Løbenr`" />
<generator class="increment" />
<discriminator column="`Trans type`" />

When trying to save a new entry of this mapped class, I get the following failure:

2006-03-19 10:52:09,828 [main] DEBUG - fetching initial value: select max(ids_.[Løbenr]) from ( select [Løbenr] from [Statsbiblioteket$SB union select [Løbenr] from Transaktioner] ) ids_
Hibernate: select max(ids_.[Løbenr]) from ( select [Løbenr] from [Statsbiblioteket$SB union select [Løbenr] from Transaktioner] ) ids_
2006-03-19 10:52:09,852 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 156, SQLState: S1000
2006-03-19 10:52:09,852 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Incorrect syntax near the keyword 'from'.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not fetch initial value for increment generator
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(
at org.hibernate.impl.SessionImpl.fireSave(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(
at $ Source)
at dk.statsbiblioteket.videnstafetten.TidsskriftAar.requestNavisionItemPriceUpdate(
at dk.statsbiblioteket.videnstafetten.TidsskriftAar.verifyNavisionItemContents(
at dk.statsbiblioteket.videnstafetten.TidsskriftAar.synchronizeNavisionItem(
at synchronizeNavisionVare.sync(
at synchronizeNavisionVare.main(
Caused by: java.sql.SQLException: Incorrect syntax near the keyword 'from'.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(
... 22 more

Note that the table name contains a blank and that this causes the configure method of the generator to think that it must access two tables.

The following patch seems to fix the problem, at least for me:

svn diff
— (revision 9658)
+++ (working copy)
@@ -51,7 +51,7 @@

String tableList = params.getProperty("tables");
if (tableList==null) tableList = params.getProperty(PersistentIdentifierGenerator.TABLES);

  • String[] tables = StringHelper.split(", ", tableList);
    + String[] tables = StringHelper.split(",", tableList);
    String column = params.getProperty("column");
    if (column==null) column = params.getProperty(PersistentIdentifierGenerator.PK);
    String schema = params.getProperty(PersistentIdentifierGenerator.SCHEMA);

What causes the problem is that StringHelper.split will tokenize the table name based on any comma and any blank. My change tells it to only split on commas (as the documentation indicates).

If you want to allow blanks after the table name separating commas, you probably need to parse the list of table names more carefully to handle quoted names with blanks in them. A slightly different solution that will probably work in most cases would be to split on the regex ",\s*", i.e. allowing any number of blanks after a comma.

  • Erik


Hibernate since ca. 3.1, verified at CVS of 24 Aug 2006


Brett Meyer
December 18, 2013, 7:57 PM

If this is still an issue on ORM 4.2 or 4.3, anyone have a test case to attach?

Brett Meyer
December 19, 2013, 10:31 PM

Note: In an attempt to clean up the HHH JIRA, we will be rejecting any ticket that sits in the "Awaiting Test Case" state for 2-3 months with no response. So, if this issue is critical to you, please attach a reproducing test case ASAP. Thanks!

Erik Bertelsen
December 20, 2013, 1:55 PM

I'm no longer working in the somewhat bizarre environment where I originally reported this bug and am consequently not in a position to test against that database with current ORM releases.

You may as well just close this bug.

Brett Meyer
December 20, 2013, 2:51 PM

Thanks for the update!




Erik Bertelsen

Fix versions






Suitable for new contributors


Requires Release Note


Pull Request





Affects versions