I'm trying to use H2 for unit testing and basic deployment scenarios
with a Hibernate and Spring framework. For more advanced scenarios
we'll be supporting PostgreSQL. So in my unit tests I have a data
source for both H2 and PostgreSQL, as well as different Hibernate
properties for each. The data sources and Hibernate properties are
pretty straightforward:
* The data sources have driver, url, username, and password (H2 URL is
"jdbc:h2:mem:test")
* The properties have dialect, show_sql, and hbm2ddl.auto (set to
"create-drop")
I'm able to use both data sources with no problem through basic JDBC
operations, so I can verify that the databases both work. The problem
comes when I try to create some new objects and insert them into the
database with Hibernate. This works just fine with PostgreSQL, but
when I switch to H2 I get an error:
09:32:45,971 INFO impl.DefaultNotificationServiceImplTests: 49 -
Initializing test class
Hibernate: insert into category (event, scope, id) values
(?, ?, ?)
09:32:46,034 WARN org.hibernate.util.JDBCExceptionReporter: 359 -
SQL Error: 42102, SQLState: 42S02
09:32:46,035 ERROR org.hibernate.util.JDBCExceptionReporter: 456 -
Table "CATEGORY" not found; SQL statement:
insert into category (event, scope, id) values (?, ?, ?)
[42102-159]
It's not that the code can't create tables in the H2 schema. I added
the following code before my Hibernate code:
Connection connection = _dataSource.getConnection();
Statement statement = connection.createStatement();
statement.execute("CREATE TABLE category(id int PRIMARY KEY, event
varchar(255), scope int)");
When I do that, everything works fine. So it appears that, in the H2
dialect or with the H2 driver or SOMETHING, the tables are not getting
auto-created.
Any help with this issue would be greatly appreciated!
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.