-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem using in-memory HSQLDB
PostPosted: Tue Apr 27, 2004 12:14 am 
Newbie

Joined: Mon Apr 26, 2004 8:32 pm
Posts: 2
I'm trying to use Hibernate with an in-memory HSQLDB data base. In my program, I load a configuration that specifies an in-memory database, then I create the database schema with SchemaUpdate (apparently successfully), then I attempt to save an object (unsuccessfully). What am I missing? Many thanks!

Phil

Hibernate 2.1 beta 3
HSQLDB 1.7.1
===hibernate.cfg.xml start====
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>

<!-- properties -->
<property name="hibernate.dialect">net.sf.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:data/test</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.show_sql">true</property>

<!-- mapping files -->
<mapping resource="hibernateforum/Location.hbm.xml"/>

</session-factory>

</hibernate-configuration>
===hibernate.cfg.xml end====
===Location.hbm.xml start===
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="hibernateforum.Location"
table="locations"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="locations"
</meta>

<id
name="id"
type="java.lang.Integer"
column="id"
unsaved-value="0"
>
<meta attribute="field-description">
@hibernate.id
generator-class="identity"
type="java.lang.Integer"
column="id"
unsaved-value="0"

</meta>
<generator class="identity" />
</id>

<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="50"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">
@hibernate.property
column="name"
length="50"
not-null="true"
</meta>
</property>
<property
name="description"
type="java.lang.String"
column="description"
not-null="true"
length="150"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">
@hibernate.property
column="description"
length="150"
not-null="true"
</meta>
</property>

<!-- associations -->

</class>
</hibernate-mapping>
===Location.hbm.xml end===
===HsqldbInMemory.java extract start===
13 // load configuration
14 Configuration config = new Configuration();
15 config.configure();
16
17 // update database schema if required
18 new SchemaUpdate(config).execute(true);
19
20 // open a session
21 SessionFactory sessionFactory = config.buildSessionFactory();
22 Session session = sessionFactory.openSession();
23
24 // persist it
25 Location roomA = new Location("Room A", "Next to lobby");
26 try
27 {
28 session.saveOrUpdate(roomA);
29 session.flush();
30 session.connection().commit();
31 }
32 catch (Exception e)
33 {
34 session.connection().rollback();
35 }
36 System.out.println("\n*** Location added: " + roomA);
37
38 // close the session
39 session.close();
40 sessionFactory.close();
===HsqldbInMemory.java extract end===
===Stack trace and debug log start===
[java] INFO - Hibernate 2.1 beta 3
[java] INFO - hibernate.properties not found
[java] INFO - using CGLIB reflection optimizer
[java] INFO - Configuration resource: /hibernate.cfg.xml
[java] DEBUG - trying to locate http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
[java] DEBUG - found http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
[java] DEBUG - hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
[java] DEBUG - hibernate.connection.driver_class=org.hsqldb.jdbcDriver
[java] DEBUG - hibernate.connection.url=jdbc:hsqldb:.
[java] DEBUG - hibernate.connection.username=sa
[java] DEBUG - hibernate.connection.password=
[java] DEBUG - hibernate.show_sql=true
[java] DEBUG - null<-org.dom4j.tree.DefaultAttribute@45e044 [Attribute: name resource value "hibernateforum/Location.hbm.xml"]
[java] INFO - Mapping resource: hibernateforum/Location.hbm.xml
[java] DEBUG - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
[java] DEBUG - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
[java] INFO - Mapping class: hibernateforum.Location -> locations
[java] DEBUG - Mapped property: id -> id, type: integer
[java] DEBUG - Mapped property: name -> name, type: string
[java] DEBUG - Mapped property: description -> description, type: string
[java] INFO - Configured SessionFactory: null
[java] DEBUG - properties: {hibernate.cglib.use_reflection_optimizer=true
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.password=
hibernate.connection.url=jdbc:hsqldb:.
hibernate.connection.username=sa
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
java.runtime.name=Java(TM) 2 Runtime Environment Standard Edition
java.runtime.version=1.4.0_02-b02
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=1.4.0_02-b02
os.name=Windows XP
os.version=5.1
sun.os.patch.level=Service Pack 1
...
}
[java] INFO - Using dialect: net.sf.hibernate.dialect.HSQLDialect
[java] INFO - Using Hibernate built-in connection pool (not for production use!)
[java] INFO - Hibernate connection pool size: 20
[java] INFO - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:.
[java] INFO - connection properties: {user=sa, password=}
[java] INFO - Running hbm2ddl schema update
[java] INFO - fetching database metadata
[java] DEBUG - total checked-out connections: 0
[java] DEBUG - opening new JDBC connection
[java] DEBUG - created connection to: jdbc:hsqldb:., Isolation Level: 1
[java] INFO - updating schema
[java] INFO - processing one-to-many association mappings
[java] INFO - processing one-to-one association property references
[java] INFO - processing foreign key constraints
[java] create table locations (id INTEGER NOT NULL IDENTITY, name VARCHAR(50) not null, description VARCHAR(150) not null)
[java] DEBUG - create table locations (id INTEGER NOT NULL IDENTITY, name VARCHAR(50) not null, description VARCHAR(150) not null)
[java] INFO - schema update complete
[java] INFO - cleaning up connection pool: jdbc:hsqldb:.
[java] INFO - processing one-to-many association mappings
[java] INFO - processing one-to-one association property references
[java] INFO - processing foreign key constraints
[java] INFO - Using dialect: net.sf.hibernate.dialect.HSQLDialect
[java] INFO - Use outer join fetching: false
[java] INFO - Using Hibernate built-in connection pool (not for production use!)
[java] INFO - Hibernate connection pool size: 20
[java] INFO - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:.
[java] INFO - connection properties: {user=sa, password=}
[java] INFO - No TransactionManagerLookup configured (use of process level read-write cache is not recommended)
[java] DEBUG - total checked-out connections: 0
[java] DEBUG - opening new JDBC connection
[java] DEBUG - created connection to: jdbc:hsqldb:., Isolation Level: 1
[java] DEBUG - returning connection to pool, pool size: 1
[java] INFO - Use scrollable result sets: true
[java] INFO - echoing all SQL to stdout
[java] INFO - Query language substitutions: {}
[java] INFO - cache provider: net.sf.hibernate.cache.JCSCacheProvider
[java] INFO - instantiating and configuring caches
[java] INFO - building session factory
[java] DEBUG - instantiating session factory with properties: {hibernate.cglib.use_reflection_optimizer=true
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.password=
hibernate.connection.url=jdbc:hsqldb:.
hibernate.connection.username=sa
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
java.runtime.name=Java(TM) 2 Runtime Environment Standard Edition
java.runtime.version=1.4.0_02-b02
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=1.4.0_02-b02
os.name=Windows XP
os.version=5.1
sun.os.patch.level=Service Pack 1
...
}
[java] DEBUG - initializing class SessionFactoryObjectFactory
[java] DEBUG - registered: 98866d1ffc299f5f00fc299f62130000 (unnamed)
[java] INFO - no JNDI name configured
[java] DEBUG - instantiated session factory
[java] DEBUG - opened session
[java] DEBUG - unsaved-value: 0
[java] DEBUG - saveOrUpdate() unsaved instance
[java] DEBUG - saving [hibernateforum.Location#<null>]
[java] DEBUG - Inserting entity: hibernateforum.Location (native id)
[java] DEBUG - about to open: 0 open PreparedStatements, 0 open ResultSets
[java] DEBUG - total checked-out connections: 0
[java] DEBUG - using pooled JDBC connection, pool size: 0
[java] DEBUG - prepared statement get: insert into locations (name, description, id) values (?, ?, null)
[java] Hibernate: insert into locations (name, description, id) values (?, ?, null)
[java] DEBUG - preparing statement
[java] DEBUG - Dehydrating entity: [hibernateforum.Location#<null>]
[java] DEBUG - binding 'Room A' to parameter: 1
[java] DEBUG - binding 'Next to lobby' to parameter: 2
[java] DEBUG - SQL Exception
[java] java.sql.SQLException: Table not found: LOCATIONS in statement [insert into locations (name, description, id) values ('Room A', 'Next to lobby', null)]
[java] at org.hsqldb.Trace.getError(Unknown Source)
[java] at org.hsqldb.jdbcResultSet.<init>(Unknown Source)
[java] at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
[java] at org.hsqldb.jdbcConnection.execute(Unknown Source)
[java] at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
[java] at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
[java] at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
[java] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
[java] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:437)
[java] at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:754)
[java] at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:642)
[java] at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1227)
[java] at HsqldbInMemory.main(HsqldbInMemory.java:28)
[java] WARN - SQL Error: -22, SQLState: S0002
[java] ERROR - Table not found: LOCATIONS in statement [insert into locations (name, description, id) values ('Room A', 'Next to lobby', null)]
[java] DEBUG - done closing: 0 open PreparedStatements, 0 open ResultSets
[java] DEBUG - closing statement
[java] DEBUG - SQL Exception
[java] java.sql.SQLException: Table not found: LOCATIONS in statement [insert into locations (name, description, id) values ('Room A', 'Next to lobby', null)]
[java] at org.hsqldb.Trace.getError(Unknown Source)
[java] at org.hsqldb.jdbcResultSet.<init>(Unknown Source)
[java] at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
[java] at org.hsqldb.jdbcConnection.execute(Unknown Source)
[java] at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
[java] at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
[java] at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
[java] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
[java] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:437)
[java] at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:754)
[java] at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:642)
[java] at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1227)
[java] at HsqldbInMemory.main(HsqldbInMemory.java:28)
[java] WARN - SQL Error: -22, SQLState: S0002
[java] ERROR - Table not found: LOCATIONS in statement [insert into locations (name, description, id) values ('Room A', 'Next to lobby', null)]
[java] ERROR - could not insert: [hibernateforum.Location]
[java] java.sql.SQLException: Table not found: LOCATIONS in statement [insert into locations (name, description, id) values ('Room A', 'Next to lobby', null)]
[java] at org.hsqldb.Trace.getError(Unknown Source)
[java] at org.hsqldb.jdbcResultSet.<init>(Unknown Source)
[java] at org.hsqldb.jdbcConnection.executeStandalone(Unknown Source)
[java] at org.hsqldb.jdbcConnection.execute(Unknown Source)
[java] at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
[java] at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
[java] at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
[java] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
[java] at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:437)
[java] at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:754)
[java] at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:642)
[java] at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1227)
[java] at HsqldbInMemory.main(HsqldbInMemory.java:28)

[java] *** Location added: hibernateforum.Location@df1832[id=<null>,name=Room A,description=Next to lobby
]
[java] DEBUG - closing session
[java] DEBUG - disconnecting session
[java] DEBUG - returning connection to pool, pool size: 1
[java] DEBUG - transaction completion
[java] INFO - closing
[java] INFO - cleaning up connection pool: jdbc:hsqldb:.
===Stack trace and debug log end===
P.S. I hope I submitted this question correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 3:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
hsqldb drops the database as soon as no more connections are left. SchemaUpdate uses it's own connection, so after SchemaUpdate has disconnected and before the Hibernate connection pool starts up there are 0 connections to the database so hsqld wipes all data.

Solutions:
- use file based hsqldb
- use hbm2dll.auto=update


Top
 Profile  
 
 Post subject: SOLVED: Problem using in-memory HSQLDB
PostPosted: Tue Apr 27, 2004 9:03 pm 
Newbie

Joined: Mon Apr 26, 2004 8:32 pm
Posts: 2
Michael,

Thanks for your reply. Placing the magic incantation
<property name="hibernate.hbm2ddl.auto">update</property>
into my hibernate.cfg.xml file did allow me to run HSQLDB in memory!

Regards,
Phil


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.