Hi there! when working through the tutorial
http://www.hibernate.org/hib_docs/v3/re ... orial.html
I get to the part where you need to disable the hbm2ddl.auto switch to prevent recreation of the database on each run, some some events can be stored.
After removing the hbm2ddl.auto property from hibernate.cfg.xml I get the following error when running ant run -Daction=store:
[java] 09:38:56,602 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLState: S0002
[java] 09:38:56,602 ERROR JDBCExceptionReporter:72 - Table not found in statement [select max(EVENT_ID) from EVENTS]
if anyone can shed some light on this for a hibernate newbie that would be great.
thanks.
$ ant run -Daction=store
cygpath: can't convert empty path
Buildfile: build.xml
clean:
[delete] Deleting directory C:\hibernate-3.0.5\devl\bin
[mkdir] Created dir: C:\hibernate-3.0.5\devl\bin
copy-resources:
[copy] Copying 3 files to C:\hibernate-3.0.5\devl\bin
compile:
[javac] Compiling 3 source files to C:\hibernate-3.0.5\devl\bin
run:
[java] 09:38:54,711 INFO Environment:464 - Hibernate 3.0.5
[java] 09:38:54,711 INFO Environment:477 - hibernate.properties not found
[java] 09:38:54,711 INFO Environment:510 - using CGLIB reflection optimize
r
[java] 09:38:54,727 INFO Environment:540 - using JDK 1.4 java.sql.Timestam
p handling
[java] 09:38:54,805 INFO Configuration:1110 - configuring from resource: /
hibernate.cfg.xml
[java] 09:38:54,805 INFO Configuration:1081 - Configuration resource: /hib
ernate.cfg.xml
[java] 09:38:55,196 INFO Configuration:444 - Mapping resource: Event.hbm.x
ml
[java] 09:38:55,352 INFO HbmBinder:260 - Mapping class: Event -> EVENTS
[java] 09:38:55,383 INFO Configuration:1222 - Configured SessionFactory: n
ull
[java] 09:38:55,399 INFO Configuration:875 - processing extends queue
[java] 09:38:55,399 INFO Configuration:879 - processing collection mapping
s
[java] 09:38:55,399 INFO Configuration:888 - processing association proper
ty references
[java] 09:38:55,399 INFO Configuration:917 - processing foreign key constr
aints
[java] 09:38:55,477 INFO DriverManagerConnectionProvider:41 - Using Hibern
ate built-in connection pool (not for production use!)
[java] 09:38:55,477 INFO DriverManagerConnectionProvider:42 - Hibernate co
nnection pool size: 1
[java] 09:38:55,477 INFO DriverManagerConnectionProvider:45 - autocommit m
ode: false
[java] 09:38:55,477 INFO DriverManagerConnectionProvider:80 - using driver
: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:data/tutorial
[java] 09:38:55,477 INFO DriverManagerConnectionProvider:86 - connection p
roperties: {user=sa, password=****}
[java] 09:38:55,930 INFO SettingsFactory:77 - RDBMS: HSQL Database Engine,
version: 1.8.0
[java] 09:38:55,930 INFO SettingsFactory:78 - JDBC driver: HSQL Database E
ngine Driver, version: 1.8.0
[java] 09:38:55,946 INFO Dialect:92 - Using dialect: org.hibernate.dialect
.HSQLDialect
[java] 09:38:55,961 INFO TransactionFactoryFactory:31 - Using default tran
saction strategy (direct JDBC transactions)
[java] 09:38:55,961 INFO TransactionManagerLookupFactory:33 - No Transacti
onManagerLookup configured (in JTA environment, use of read-write or transaction
al second-level cache is not recommended)
[java] 09:38:55,961 INFO SettingsFactory:125 - Automatic flush during befo
reCompletion(): disabled
[java] 09:38:55,961 INFO SettingsFactory:129 - Automatic session close at
end of transaction: disabled
[java] 09:38:55,961 INFO SettingsFactory:136 - JDBC batch size: 15
[java] 09:38:55,961 INFO SettingsFactory:139 - JDBC batch updates for vers
ioned data: disabled
[java] 09:38:55,977 INFO SettingsFactory:144 - Scrollable result sets: ena
bled
[java] 09:38:55,977 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): d
isabled
[java] 09:38:55,977 INFO SettingsFactory:160 - Connection release mode: nu
ll
[java] 09:38:55,977 INFO SettingsFactory:187 - Default batch fetch size: 1
[java] 09:38:55,977 INFO SettingsFactory:191 - Generate SQL with comments:
disabled
[java] 09:38:55,977 INFO SettingsFactory:195 - Order SQL updates by primar
y key: disabled
[java] 09:38:55,977 INFO SettingsFactory:334 - Query translator: org.hiber
nate.hql.ast.ASTQueryTranslatorFactory
[java] 09:38:55,977 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTran
slatorFactory
[java] 09:38:55,977 INFO SettingsFactory:203 - Query language substitution
s: {}
[java] 09:38:55,977 INFO SettingsFactory:209 - Second-level cache: enabled
[java] 09:38:55,977 INFO SettingsFactory:213 - Query cache: disabled
[java] 09:38:55,977 INFO SettingsFactory:321 - Cache provider: org.hiberna
te.cache.EhCacheProvider
[java] 09:38:55,993 INFO SettingsFactory:228 - Optimize cache for minimal
puts: disabled
[java] 09:38:56,008 INFO SettingsFactory:237 - Structured second-level cac
he entries: disabled
[java] 09:38:56,008 INFO SettingsFactory:257 - Echoing all SQL to stdout
[java] 09:38:56,008 INFO SettingsFactory:261 - Statistics: disabled
[java] 09:38:56,008 INFO SettingsFactory:265 - Deleted entity synthetic id
entifier rollback: disabled
[java] 09:38:56,008 INFO SettingsFactory:279 - Default entity-mode: pojo
[java] 09:38:56,149 INFO SessionFactoryImpl:152 - building session factory
[java] 09:38:56,165 WARN Configurator:126 - No configuration found. Config
uring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/hib
ernate-3.0.5/devl/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[java] 09:38:56,540 INFO SessionFactoryObjectFactory:82 - Not binding fact
ory to JNDI, no JNDI name configured
[java] 09:38:56,540 INFO SessionFactoryImpl:379 - Checking 0 named queries
[java] 09:38:56,602 WARN JDBCExceptionReporter:71 - SQL Error: -22, SQLSta
te: S0002
[java] 09:38:56,602 ERROR JDBCExceptionReporter:72 - Table not found in sta
tement [select max(EVENT_ID) from EVENTS]
[java] org.hibernate.exception.SQLGrammarException: could not fetch initial
value
[java] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeC
onverter.java:70)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExcep
tionHelper.java:43)
[java] at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerato
r.java:107)
[java] at org.hibernate.id.IncrementGenerator.generate(IncrementGenerat
or.java:45)
[java] at org.hibernate.event.def.AbstractSaveEventListener.saveWithGen
eratedId(AbstractSaveEventListener.java:85)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.save
WithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
[java] at org.hibernate.event.def.DefaultSaveEventListener.saveWithGene
ratedOrRequestedId(DefaultSaveEventListener.java:33)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.enti
tyIsTransient(DefaultSaveOrUpdateEventListener.java:173)
[java] at org.hibernate.event.def.DefaultSaveEventListener.performSaveO
rUpdate(DefaultSaveEventListener.java:27)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSa
veOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
[java] at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
[java] at EventManager.createAndStoreEvent(Unknown Source)
[java] at EventManager.main(Unknown Source)
[java] Caused by: java.sql.SQLException: Table not found in statement [sele
ct max(EVENT_ID) from EVENTS]
[java] at org.hsqldb.jdbc.Util.throwError(Unknown Source)
[java] at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
[java] at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Sourc
e)
[java] at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerato
r.java:86)
[java] ... 11 more
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 4 seconds
Hibernate version: 3.0.5
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: