I ran through this entire chapter. There was nothing new to what I was
already doing. As I stated, everything works fine in MySql. The tables get
created, then the data gets populated, then the dbunit tests get run just
fine. No issues.
But when I move to hsql, the sql file from the hibernate plugin gets
generated, but I get several different failures now.
*1. When I use the <drop>false</drop>, the import.sql that is generated does
not have table drop statements, thus I get this error:*
*[myproject] ERROR [main] SchemaExport.execute(202) | schema export
unsuccessful
org.hibernate.JDBCException: Error during import script execution
at
org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:258)
at
org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:192)
at
org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
...
Caused by: java.sql.SQLException: Table already exists: USER_ROLE in
statement [create table user_role]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at
com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:1006)
at
org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:254)
*
*2. When I use the <drop>true</drop> my iport.sql that gets generated starts
like:*
*alter table app_user drop constraint FK459C57294AD68248;
alter table user_role drop constraint FK143BF46AE8EA6EF6;
alter table user_role drop constraint FK143BF46A43BFAB16;
drop table address if exists;
drop table app_user if exists;
drop table role if exists;
drop table user_role if exists;*
*But then I get this error:*
*Caused by: java.sql.SQLException: Table not found: APP_USER in statement
[alter table app_user]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at
org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at
org.apache.commons.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
at
org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:254)*
So it appears the sql that is generated is failing. The app_user table does
not exist because this is a memory db right?
*Then I tried to just scale everything back to what you had, but adding
execution phase like:*
*<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
</configuration>
<executions>
<execution>
<id>hbm2ddl</id>
<phase>process-test-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>${jdbc.groupId}</groupId>
<artifactId>${jdbc.artifactId}</artifactId>
<version>${jdbc.version}</version>
</dependency>
</dependencies>
</plugin>
*
*
and I still get:*
*[myproject] DEBUG [main] RoleDaoJpaTest.prepareDataSet(34) | Invoked
prepareDataSet()
[myproject] INFO [main] RoleDaoJpaTest.toString(168) |
==========================================================
[myproject] INFO [main] RoleDaoJpaTest.toString(169) | package
org.dbunit.dataset.class org.dbunit.dataset.ReplacementDataSet
[myproject] INFO [main] RoleDaoJpaTest.toString(170) |
==========================================================
[myproject] INFO [main] RoleDaoJpaTest.toString(171) |
[EMAIL PROTECTED]
_dataSet=[address, role, app_user, user_role]
_objectMap={}
_substringMap={}
_startDelim=<null>
_endDelim=<null>
]
[myproject] INFO [main] RoleDaoJpaTest.toString(177) |
==========================================================
[myproject] DEBUG [main] RoleDaoJpaTest.loadSeedData(73) | Exception in
initializing database
org.dbunit.dataset.NoSuchTableException: address
org.dbunit.dataset.NoSuchTableException: address
at
org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:223)
at
org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:223)
*
Then looking around, it seems to be failing like:
*[myproject] INFO [main] SchemaExport.execute(154) | Running hbm2ddl schema
export
[myproject] DEBUG [main] SchemaExport.execute(170) | import file not found:
/import.sql
[myproject] INFO [main] SchemaExport.execute(179) | exporting generated
schema to database
[myproject] DEBUG [main] SchemaExport.execute(303) | alter table app_user
drop foreign key FK459C57294AD68248
[myproject] DEBUG [main] SchemaExport.drop(288) | Unsuccessful: alter table
app_user drop foreign key FK459C57294AD68248
[myproject] DEBUG [main] SchemaExport.drop(289) | Table not found: APP_USER
in statement [alter table app_user]
[myproject] DEBUG [main] SchemaExport.execute(303) | alter table user_role
drop foreign key FK143BF46AE8EA6EF6
[myproject] DEBUG [main] SchemaExport.drop(288) | Unsuccessful: alter table
user_role drop foreign key FK143BF46AE8EA6EF6
[myproject] DEBUG [main] SchemaExport.drop(289) | Column not found: FOREIGN
in statement [alter table user_role drop foreign]
[myproject] DEBUG [main] SchemaExport.execute(303) | alter table user_role
drop foreign key FK143BF46A43BFAB16
[myproject] DEBUG [main] SchemaExport.drop(288) | Unsuccessful: alter table
user_role drop foreign key FK143BF46A43BFAB16
[myproject] DEBUG [main] SchemaExport.drop(289) | Column not found: FOREIGN
in statement [alter table user_role drop foreign]
[myproject] DEBUG [main] SchemaExport.execute(303) | drop table if exists
address
[myproject] DEBUG [main] SchemaExport.execute(303) | drop table if exists
app_user
[myproject] DEBUG [main] SchemaExport.execute(303) | drop table if exists
role
[myproject] DEBUG [main] SchemaExport.execute(303) | drop table if exists
user_role
[myproject] DEBUG [main] SchemaExport.execute(303) | create table address
(id bigint not null auto_increment, version integer, address varchar(25) not
null, city varchar(25) not null, country varchar(2) not null, postal_code
varchar(25) not null, province varchar(25) not null, primary key(id))
[myproject] ERROR [main] SchemaExport.create(274) | Unsuccessful: create
table address (id bigint not null auto_increment, version integer, address
varchar(25) not null, city varchar(25) not null, country varchar(2) not
null, postal_code varchar(25) not null, province varchar(25) not null,
primary key (id))
[myproject] ERROR [main] SchemaExport.create(275) | Unexpected token:
AUTO_INCREMENT in statement [create table address (id bigint not null
auto_increment]
[myproject] DEBUG [main] SchemaExport.execute(303) | create table app_user
(id bigint not null auto_increment, version integer, confirmPassword
varchar(255), email varchar(50) not null, first_name varchar(50) not null,
last_name varchar(50) not null, middle_name varchar(50), password
varchar(100) not null, password_hint varchar(50), phone_number varchar(25),
username varchar(25) not null, website varchar(50), address_fk bigint,
primary key (id))
[myproject] ERROR [main] SchemaExport.create(274) | Unsuccessful: create
table app_user (id bigint not null auto_increment, version integer,
confirmPassword varchar(255), email varchar(50) not null, first_name
varchar(50) not null, last_name varchar(50) not null, middle_name
varchar(50), password varchar(100) not null, password_hint varchar(50),
phone_number varchar(25), username varchar(25) not null, website
varchar(50), address_fk bigint, primary key (id))
[myproject] ERROR [main] SchemaExport.create(275) | Unexpected token:
AUTO_INCREMENT in statement [create table app_user (id bigint not null
auto_increment]
[myproject] DEBUG [main] SchemaExport.execute(303) | create table role (id
bigint not null auto_increment, version integer, description varchar(255)
not null, name varchar(64) not null, primary key (id))
[myproject] ERROR [main] SchemaExport.create(274) | Unsuccessful: create
table role (id bigint not null auto_increment, version integer, description
varchar(255) not null, name varchar(64) not null, primary key (id))
[myproject] ERROR [main] SchemaExport.create(275) | Unexpected token:
AUTO_INCREMENT in statement [create table role (id bigint not null
auto_increment]
[myproject] DEBUG [main] SchemaExport.execute(303) | create table user_role
(user_id bigint not null, role_id bigint not null, primary key (user_id,
role_id))
[myproject] DEBUG [main] SchemaExport.execute(303) | alter table app_user
add index FK459C57294AD68248 (address_fk), add constraint FK459C57294AD68248
foreign key (address_fk) references address (id)
[myproject] ERROR [main] SchemaExport.create(274) | Unsuccessful: alter
table app_user add index FK459C57294AD68248 (address_fk), add
constraintFK459C57294AD68248 foreign key (address_fk) references address
(id)
[myproject] ERROR [main] SchemaExport.create(275) | Table not found:
APP_USER in statement [alter table app_user]
[myproject] DEBUG [main] SchemaExport.execute(303) | alter table user_role
add index FK143BF46AE8EA6EF6 (user_id), add constraint FK143BF46AE8EA6EF6
foreign key (user_id) references app_user (id)
[myproject] ERROR [main] SchemaExport.create(274) | Unsuccessful: alter
table user_role add index FK143BF46AE8EA6EF6 (user_id), add constraint
FK143BF46AE8EA6EF6 foreign key (user_id) references app_user (id)
[myproject] ERROR [main] SchemaExport.create(275) | Wrong data type:
FK143BF46AE8EA6EF6 in statement [alter table user_role add index
FK143BF46AE8EA6EF6]
[myproject] DEBUG [main] SchemaExport.execute(303) | alter table user_role
add index FK143BF46A43BFAB16 (role_id), add constraint FK143BF46A43BFAB16
foreign key (role_id) references role (id)
[myproject] ERROR [main] SchemaExport.create(274) | Unsuccessful: alter
table user_role add index FK143BF46A43BFAB16 (role_id), add constraint
FK143BF46A43BFAB16 foreign key (role_id) references role (id)
[myproject] ERROR [main] SchemaExport.create(275) | Wrong data type:
FK143BF46A43BFAB16 in statement [alter table user_role add index
FK143BF46A43BFAB16]
[myproject] INFO [main] SchemaExport.execute(196) | schema export complete
[myproject] DEBUG [main] SessionFactoryImpl.checkNamedQueries(392) |
Checking 1 named HQL queries
[myproject] DEBUG [main] SessionFactoryImpl.checkNamedQueries(400) |
Checking named query: User-byRole
[myproject] DEBUG [main] QueryTranslatorImpl.parse(246) | parse() - HQL:
select u from com.baselogic.domain.User u where (select r from
com.baselogic.domain.Role r where r.name = :roleName) in elements (u.roles)
*
On Sun, Apr 27, 2008 at 7:12 AM, Brian E. Fox <[EMAIL PROTECTED]>
wrote:
> Chapter 7 of Maven: The Definitive Guide shows a multimodule example
> that happens to use Hibernate: http://www.sonatype.com/book
>
> -----Original Message-----
> From: Mick Knutson [mailto:[EMAIL PROTECTED]
> Sent: Saturday, April 26, 2008 10:11 AM
> To: maven
> Subject: [m2] can't get hibernate plugin to work with hsql
>
> zI am trying to run hibernate to generate sql, populate my db and then
> run
> some tests.
> Well, if I use MySql, I do not have any issues at all. But when I switch
> to
> hsql, i can't get the databasse tables to be created, then I get a table
> not
> exist error in dbunit.
>
> Here is my hibernate plugin:
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>hibernate3-maven-plugin</artifactId>
> <version>2.1</version>
> <configuration>
> <components>
> <component>
> <name>hbm2ddl</name>
>
> <implementation>annotationconfiguration</implementation>
> </component>
> <component>
> <name>hbm2hbmxml</name>
>
> <outputDirectory>src/main/resources</outputDirectory>
> </component>
> </components>
> <componentProperties>
> <drop>true</drop>
>
> <configurationfile>/src/main/resources/hibernate.cfg.xml</configurationf
> ile>
> <jdk5>true</jdk5>
> <skip>${maven.test.skip}</skip>
> </componentProperties>
> </configuration>
> <executions>
> <execution>
> <id>hbm2ddl</id>
> <phase>process-test-resources</phase>
> <goals>
> <goal>hbm2ddl</goal>
> </goals>
> </execution>
> </executions>
> <dependencies>
> <dependency>
> <groupId>${jdbc.groupId}</groupId>
> <artifactId>${jdbc.artifactId}</artifactId>
> <version>${jdbc.version}</version>
> </dependency>
> </dependencies>
> </plugin>
>
> So what am I missing? Why do the tables for Mysql but with HSQL they do
> not?
> Also, I do not see any files generated in src/main/resources/
>
> Here is the trace when I run hibernate alone:
>
> [myproject] INFO [main] SchemaExport.execute(154) | Running hbm2ddl
> schema
> export
> [myproject] DEBUG [main] SchemaExport.execute(170) | import file not
> found:
> /import.sql
> [myproject] INFO [main] SchemaExport.execute(179) | exporting generated
> schema to database
> [myproject] INFO [main] DriverManagerConnectionProvider.configure(41) |
> Using Hibernate built-in connection pool (not for production use!)
> [myproject] INFO [main] DriverManagerConnectionProvider.configure(42) |
> Hibernate connection pool size: 20
> [myproject] INFO [main] DriverManagerConnectionProvider.configure(45) |
> autocommit mode: false
> [myproject] INFO [main] DriverManagerConnectionProvider.configure(80) |
> using driver: org.hsqldb.jdbcDriver at URL:
> jdbc:hsqldb:file:target/testd
> b-hsql;shutdown=true
> [myproject] INFO [main] DriverManagerConnectionProvider.configure(83) |
> connection properties: {user=sa, password=}
> [myproject] DEBUG [main]
> DriverManagerConnectionProvider.getConnection(93) |
> total checked-out connections: 0
> [myproject] DEBUG [main]
> DriverManagerConnectionProvider.getConnection(109)
> | opening new JDBC connection
> [myproject] DEBUG [main]
> DriverManagerConnectionProvider.getConnection(115)
> | created connection to: jdbc:hsqldb:file:target/testdb-hsql;shutdown
> =true, Isolation Level: 2
> alter table app_user drop constraint FK459C57294AD68248;
> [myproject] DEBUG [main] SchemaExport.execute(303) | alter table
> app_user
> drop constraint FK459C57294AD68248;
> [myproject] DEBUG [main] SchemaExport.drop(288) | Unsuccessful: alter
> table
> app_user drop constraint FK459C57294AD68248
> [myproject] DEBUG [main] SchemaExport.drop(289) | Table not found:
> APP_USER
> in statement [alter table app_user]
> alter table user_role drop constraint FK143BF46AE8EA6EF6;
> [myproject] DEBUG [main] SchemaExport.execute(303) | alter table
> user_role
> drop constraint FK143BF46AE8EA6EF6;
> [myproject] DEBUG [main] SchemaExport.drop(288) | Unsuccessful: alter
> table
> user_role drop constraint FK143BF46AE8EA6EF6
> [myproject] DEBUG [main] SchemaExport.drop(289) | Table not found:
> USER_ROLE
> in statement [alter table user_role]
> alter table user_role drop constraint FK143BF46A43BFAB16;
> [myproject] DEBUG [main] SchemaExport.execute(303) | alter table
> user_role
> drop constraint FK143BF46A43BFAB16;
> [myproject] DEBUG [main] SchemaExport.drop(288) | Unsuccessful: alter
> table
> user_role drop constraint FK143BF46A43BFAB16
> [myproject] DEBUG [main] SchemaExport.drop(289) | Table not found:
> USER_ROLE
> in statement [alter table user_role]
> drop table address if exists;
> [myproject] DEBUG [main] SchemaExport.execute(303) | drop table address
> if
> exists;
> drop table app_user if exists;
> [myproject] DEBUG [main] SchemaExport.execute(303) | drop table app_user
> if
> exists;
> drop table role if exists;
> [myproject] DEBUG [main] SchemaExport.execute(303) | drop table role if
> exists;
> drop table user_role if exists;
> [myproject] DEBUG [main] SchemaExport.execute(303) | drop table
> user_role if
> exists;
> create table address (id bigint generated by default as identity (start
> with
> 1), version integer, address varchar(25) not null, city varchar(25)
> not null, country varchar(2) not null, postal_code varchar(25) not null,
> province varchar(25) not null, primary key (id));
> [myproject] DEBUG [main] SchemaExport.execute(303) | create table
> address
> (id bigint generated by default as identity (start with 1), version int
> eger, address varchar(25) not null, city varchar(25) not null, country
> varchar(2) not null, postal_code varchar(25) not null, province
> varchar(25
> ) not null, primary key (id));
> create table app_user (id bigint generated by default as identity (start
> with 1), version integer, confirmPassword varchar(255), email varchar(50
> ) not null, first_name varchar(50) not null, last_name varchar(50) not
> null,
> middle_name varchar(50), password varchar(100) not null, password_hi
> nt varchar(50), phone_number varchar(25), username varchar(25) not null,
> website varchar(50), address_fk bigint, primary key (id));
> [myproject] DEBUG [main] SchemaExport.execute(303) | create table
> app_user
> (id bigint generated by default as identity (start with 1), version in
> teger, confirmPassword varchar(255), email varchar(50) not null,
> first_name
> varchar(50) not null, last_name varchar(50) not null, middle_name var
> char(50), password varchar(100) not null, password_hint varchar(50),
> phone_number varchar(25), username varchar(25) not null, website
> varchar(50)
> , address_fk bigint, primary key (id));
> create table role (id bigint generated by default as identity (start
> with
> 1), version integer, description varchar(255) not null, name varchar(64
> ) not null, primary key (id));
> [myproject] DEBUG [main] SchemaExport.execute(303) | create table role
> (id
> bigint generated by default as identity (start with 1), version intege
> r, description varchar(255) not null, name varchar(64) not null, primary
> key
> (id));
> create table user_role (user_id bigint not null, role_id bigint not
> null,
> primary key (user_id, role_id));
> [myproject] DEBUG [main] SchemaExport.execute(303) | create table
> user_role
> (user_id bigint not null, role_id bigint not null, primary key (user_
> id, role_id));
> alter table app_user add constraint FK459C57294AD68248 foreign key
> (address_fk) references address;
> [myproject] DEBUG [main] SchemaExport.execute(303) | alter table
> app_user
> add constraint FK459C57294AD68248 foreign key (address_fk) references a
> ddress;
> alter table user_role add constraint FK143BF46AE8EA6EF6 foreign key
> (user_id) references app_user;
> [myproject] DEBUG [main] SchemaExport.execute(303) | alter table
> user_role
> add constraint FK143BF46AE8EA6EF6 foreign key (user_id) references app
> _user;
> alter table user_role add constraint FK143BF46A43BFAB16 foreign key
> (role_id) references role;
> [myproject] DEBUG [main] SchemaExport.execute(303) | alter table
> user_role
> add constraint FK143BF46A43BFAB16 foreign key (role_id) references rol
> e;
> [myproject] INFO [main] SchemaExport.execute(196) | schema export
> complete
> [myproject] DEBUG [main]
> DriverManagerConnectionProvider.closeConnection(129) | returning
> connection
> to pool, pool size: 1
> [myproject] INFO [main] DriverManagerConnectionProvider.close(147) |
> cleaning up connection pool:
> jdbc:hsqldb:file:target/testdb-hsql;shutdown=tr
> ue
> [WARNING] 3 errors occurred while performing <hbm2ddl>.
> *[ERROR] Error #1: java.sql.SQLException: Table not found: APP_USER in
> statement [alter table app_user]
> [ERROR] Error #1: java.sql.SQLException: Table not found: USER_ROLE in
> statement [alter table user_role]
> [ERROR] Error #1: java.sql.SQLException: Table not found: USER_ROLE in
> statement [alter table user_role]
> [INFO]
> ------------------------------------------------------------------------
> *
>
>
> I would alos assume that I could point dbvisualizer at this hsql db and
> I
> could see the tables which I can't. It connects, but there are no
> tables.
>
> --
> Thanks,
> Mick Knutson
>
> http://www.baselogic.com
> http://www.blincmagazine.com
> http://www.linkedin.com/in/mickknutson
> http://www.djmick.com
> http://www.myspace.com/mickknutson
> http://www.myspace.com/BLiNCMagazine
> http://tahoe.baselogic.com
> ---
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Thanks,
Mick Knutson
http://www.baselogic.com
http://www.blincmagazine.com
http://www.linkedin.com/in/mickknutson
http://www.djmick.com
http://www.myspace.com/mickknutson
http://www.myspace.com/BLiNCMagazine
http://tahoe.baselogic.com
---