org.hibernate.exception.GenericJDBCException: could not fetch initial value for increment generator

Hibernate JIRA | Erik Bertelsen | 1 decade ago
  1. 0

    The following change to IncrementGenerator.java 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): <hibernate-mapping> <class name="dk.statsbiblioteket.navision.integration.Transaction" table="`REGNSKAB$SB Transaktioner`" dynamic-update="true"> <id name="lbNummer"> <column name="`Løbenr`" /> <generator class="increment" /> </id> <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 org.hibernate.id.IncrementGenerator - 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(SQLStateConverter.java:103) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107) at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:90) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:534) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:522) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518) 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(ThreadLocalSessionContext.java:301) at $Proxy0.save(Unknown Source) at dk.statsbiblioteket.navision.integration.UpdateItemPriceTransactionDAO.save(UpdateItemPriceTransactionDAO.java:45) at dk.statsbiblioteket.videnstafetten.TidsskriftAar.requestNavisionItemPriceUpdate(TidsskriftAar.java:1188) at dk.statsbiblioteket.videnstafetten.TidsskriftAar.verifyNavisionItemContents(TidsskriftAar.java:1132) at dk.statsbiblioteket.videnstafetten.TidsskriftAar.synchronizeNavisionItem(TidsskriftAar.java:1077) at synchronizeNavisionVare.sync(synchronizeNavisionVare.java:95) at synchronizeNavisionVare.main(synchronizeNavisionVare.java:31) Caused by: java.sql.SQLException: Incorrect syntax near the keyword 'from'. at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365) at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781) at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224) at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628) at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:418) at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:693) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:85) ... 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 Index: IncrementGenerator.java =================================================================== --- IncrementGenerator.java (revision 9658) +++ IncrementGenerator.java (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 JIRA | 1 decade ago | Erik Bertelsen
    org.hibernate.exception.GenericJDBCException: could not fetch initial value for increment generator
  2. 0

    The following change to IncrementGenerator.java 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): <hibernate-mapping> <class name="dk.statsbiblioteket.navision.integration.Transaction" table="`REGNSKAB$SB Transaktioner`" dynamic-update="true"> <id name="lbNummer"> <column name="`Løbenr`" /> <generator class="increment" /> </id> <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 org.hibernate.id.IncrementGenerator - 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(SQLStateConverter.java:103) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107) at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:90) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186) at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175) at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:534) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:522) at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518) 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(ThreadLocalSessionContext.java:301) at $Proxy0.save(Unknown Source) at dk.statsbiblioteket.navision.integration.UpdateItemPriceTransactionDAO.save(UpdateItemPriceTransactionDAO.java:45) at dk.statsbiblioteket.videnstafetten.TidsskriftAar.requestNavisionItemPriceUpdate(TidsskriftAar.java:1188) at dk.statsbiblioteket.videnstafetten.TidsskriftAar.verifyNavisionItemContents(TidsskriftAar.java:1132) at dk.statsbiblioteket.videnstafetten.TidsskriftAar.synchronizeNavisionItem(TidsskriftAar.java:1077) at synchronizeNavisionVare.sync(synchronizeNavisionVare.java:95) at synchronizeNavisionVare.main(synchronizeNavisionVare.java:31) Caused by: java.sql.SQLException: Incorrect syntax near the keyword 'from'. at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365) at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781) at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224) at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628) at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:418) at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:693) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76) at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:85) ... 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 Index: IncrementGenerator.java =================================================================== --- IncrementGenerator.java (revision 9658) +++ IncrementGenerator.java (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 JIRA | 1 decade ago | Erik Bertelsen
    org.hibernate.exception.GenericJDBCException: could not fetch initial value for increment generator
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Upgrading to Confluence 2.7.4 Fails with invalid column names - Atlassian Documentation

    atlassian.com | 3 months ago
    com.atlassian.upgrade.UpgradeException: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT count\(*) FROM OS_PROPERTYENTRY WHERE ENTITY_NAME=? AND ENTITY_ID=?|SELECT count(*) FROM OS_PROPERTYENTRY WHERE ENTITY_NAME=? AND ENTITY_ID=?]; nested exception is java.sql.SQLException: Invalid column name 'ENTITY_NAME'.

  1. ruifung 1 times, last 3 months ago
12 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.sql.SQLException

    Incorrect syntax near the keyword 'from'.

    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic()
  2. jTDS
    JtdsPreparedStatement.executeQuery
    1. net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:365)
    2. net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2781)
    3. net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2224)
    4. net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:628)
    5. net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:418)
    6. net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:693)
    6 frames
  3. c3p0:JDBC DataSources/Resource Pools
    NewProxyPreparedStatement.executeQuery
    1. com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    1 frame
  4. Hibernate
    IncrementGenerator.generate
    1. org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:85)
    2. org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
    2 frames
  5. Hibernate
    SessionImpl.save
    1. org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:90)
    2. org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
    3. org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
    4. org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
    5. org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
    6. org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
    7. org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:534)
    8. org.hibernate.impl.SessionImpl.save(SessionImpl.java:522)
    9. org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
    9 frames
  6. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    4. java.lang.reflect.Method.invoke(Unknown Source)
    4 frames
  7. Hibernate
    ThreadLocalSessionContext$TransactionProtectionWrapper.invoke
    1. org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
    1 frame
  8. Unknown
    $Proxy0.save
    1. $Proxy0.save(Unknown Source)
    1 frame
  9. dk.statsbiblioteket.navision
    UpdateItemPriceTransactionDAO.save
    1. dk.statsbiblioteket.navision.integration.UpdateItemPriceTransactionDAO.save(UpdateItemPriceTransactionDAO.java:45)
    1 frame
  10. dk.statsbiblioteket.videnstafetten
    TidsskriftAar.synchronizeNavisionItem
    1. dk.statsbiblioteket.videnstafetten.TidsskriftAar.requestNavisionItemPriceUpdate(TidsskriftAar.java:1188)
    2. dk.statsbiblioteket.videnstafetten.TidsskriftAar.verifyNavisionItemContents(TidsskriftAar.java:1132)
    3. dk.statsbiblioteket.videnstafetten.TidsskriftAar.synchronizeNavisionItem(TidsskriftAar.java:1077)
    3 frames
  11. Unknown
    synchronizeNavisionVare.main
    1. synchronizeNavisionVare.sync(synchronizeNavisionVare.java:95)
    2. synchronizeNavisionVare.main(synchronizeNavisionVare.java:31)
    2 frames