Hi,
I've recently started a small project that will use Hibernate.
I use Hibernate core version 3.3.1.GA.
For testing, we will use Hsqldb in file mode.
I have two persistent classes, two mapping files and a hibernate.cfg.xml file.
However, even though I've configured Hibernate to automatically create the tables, this fails for some reason.
Here is the Hibernate configuration file:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<!--property name="connection.url">jdbc:hsqldb:mem:Test</property-->
<property name="connection.url">jdbc:hsqldb:file:target/testdb</property>
<!-- property name="connection.url">jdbc:hsqldb:hsql://localhost</property -->
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="se/dina/myplaces/domain/Feed.hbm.xml"/>
<mapping resource="se/dina/myplaces/domain/Place.hbm.xml"/>
</session-factory>
</hibernate-configuration>
As you can see, I have tried to use the database both in file mode an in in-memory mode, but with the same result. I have also set "hbm2dll" to "update" to recreate the database on each test run.
From what I understand, Hibernate tries to do exactly this, but fails somehow.
It seems that the SQL for creating the tables are misinterpretet, even though I have compared it with the HSQLDB documentation and to me, it seems correct.
Here is the complete error message:
Code:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running se.dina.myplaces.domain.PlaceTest
50 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
73 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
93 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
98 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
168 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
168 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
274 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : se/dina/myplaces/domain/Feed.hbm.xml
474 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: se.dina.myplaces.domain.Feed -> FEEDS
503 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : se/dina/myplaces/domain/Place.hbm.xml
547 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: se.dina.myplaces.domain.Place -> PLACES
555 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
556 [main] INFO org.hibernate.cfg.HbmBinder - Mapping collection: se.dina.myplaces.domain.Place.feeds -> FEEDS
681 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
682 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
682 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
686 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:file:target/testdb
686 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
928 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 1.8.0
928 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
944 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
951 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
962 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
985 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
1002 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
1002 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
1004 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
1005 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
1005 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): disabled
1005 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
1006 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
1009 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
1015 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
1015 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
1018 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
1020 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
1020 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
1021 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
1021 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
1021 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
1026 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
1027 [main] INFO org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge - Cache provider: org.hibernate.cache.NoCacheProvider
1027 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
1027 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
1031 [main] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
1033 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
1033 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
1033 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
1033 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
1084 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
1281 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
1286 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
1286 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
1292 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema
1318 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: FEEDS
1320 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: PLACES
1325 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: FEEDS
1326 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: PLACES
1330 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table FEEDS (FEED_ID varchar(255) generated by default as identity (start with 1), URL varchar(255), placeId varchar(255) not null, primary key (FEED_ID))
1330 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Wrong data type: FEED_ID in statement [create table FEEDS (FEED_ID varchar(255) generated by default as identity (start with 1)]
1330 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table PLACES (NATIVE_PLACE_ID varchar(255) generated by default as identity (start with 1), placeId varchar(255), title varchar(255), primary key (NATIVE_PLACE_ID))
1330 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Wrong data type: NATIVE_PLACE_ID in statement [create table PLACES (NATIVE_PLACE_ID varchar(255) generated by default as identity (start with 1)]
1331 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table FEEDS add constraint FK3FAD6754FD7B foreign key (placeId) references PLACES
1331 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Table not found: FEEDS in statement [alter table FEEDS]
1331 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete
Hibernate: insert into PLACES (NATIVE_PLACE_ID, placeId, title) values (null, ?, ?)
1433 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -22, SQLState: S0002
1433 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Table not found in statement [insert into PLACES (NATIVE_PLACE_ID, placeId, title) values (null, ?, ?)]
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.59 sec <<< FAILURE!
I am stuck for the time being, and I would be very grateful for any hints and tricks that can help me get through this problem.
UPDATE: I have now changed the configuration to use MySql instead, but I get a similar problem nonetheless:
Code:
1556 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - Running hbm2ddl schema update
1556 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - fetching database metadata
1557 [main] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - updating schema
1593 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: FEEDS
1594 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: PLACES
1595 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: FEEDS
1596 [main] INFO org.hibernate.tool.hbm2ddl.DatabaseMetadata - table not found: PLACES
1609 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table FEEDS (FEED_ID varchar(255) not null auto_increment, URL varchar(255), placeId varchar(255) not null, primary key (FEED_ID)) ENGINE=InnoDB
1609 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Incorrect column specifier for column 'FEED_ID'
1612 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: create table PLACES (NATIVE_PLACE_ID varchar(255) not null auto_increment, placeId varchar(255), title varchar(255), primary key (NATIVE_PLACE_ID)) ENGINE=InnoDB
1612 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Incorrect column specifier for column 'NATIVE_PLACE_ID'
1613 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table FEEDS add index FK3FAD6754FD7B (placeId), add constraint FK3FAD6754FD7B foreign key (placeId) references PLACES (NATIVE_PLACE_ID)
So obviously there is something wrong with my configuration or code.
Thanks in advance,
Anders