I am trying to learn Hibernate from Java Persistence with hibernate by Gavin King.
I just downloaded the examples given in the book from this location http://downloads.jboss.org/hibernate/caveatemptor/jpwh-gettingstarted-070401.zip
I started my HSQL db using ant startdb and database started successfully.
When trying to run the target schemaexport I am getting the below error..
schemaexport: [hibernatetool]
Executing Hibernate Tool with a
Standard Configuration [hibernatetool]
1. task: hbm2ddl (Generates database schema) [hibernatetool] 18:07:56,555
INFO Environment:500 – Hibernate
3.2.0.cr5 [hibernatetool] 18:07:56,555 INFO Environment:533 –
hibernate.properties not fo und
[hibernatetool] 18:07:56,555 INFO
Environment:667 – Bytecode provider
name : cg lib [hibernatetool]
18:07:56,571 INFO Environment:584 –
using JDK 1.4 java.sql.Time stamp
handling [hibernatetool] 18:07:56,617
INFO Configuration:1384 – configuring
from file: h ibernate.cfg.xml
[hibernatetool] 18:07:56,680 INFO
Configuration:507 – Reading mappings
from res ource: hello/Message.hbm.xml
[hibernatetool] 18:07:56,758 INFO
HbmBinder:300 – Mapping class:
hello.Message
-> MESSAGES [hibernatetool] 18:07:56,851 INFO Configuration:1465
– Configured SessionFactor y: null [hibernatetool] 18:07:56,851 INFO
Dialect:141 – Using dialect:
org.hibernate.di alect.HSQLDialect
[hibernatetool] 18:07:56,914 INFO
SchemaExport:154 – Running hbm2ddl
schema exp ort [hibernatetool]
18:07:56,914 INFO SchemaExport:174 –
writing generated schema t o file:
C:\Users\Ramesh\Desktop\Tutorials\hibernate\Hibernate
Code samples\jpwh-
gettingstarted-070401\helloworld-native\helloworld-ddl.sql
[hibernatetool] 18:07:56,914 INFO
SchemaExport:179 – exporting generated
schema to database [hibernatetool]
18:07:56,914 INFO
C3P0ConnectionProvider:50 – C3P0 using
driver : org.hsqldb.jdbcDriver at URL:
jdbc:hsqldb:hsql://localhost
[hibernatetool] 18:07:56,914 INFO
C3P0ConnectionProvider:51 – Connection
proper ties: {user=sa} [hibernatetool]
18:07:56,914 INFO
C3P0ConnectionProvider:54 – autocommit
mode: false [hibernatetool]
18:08:26,554 WARN
BasicResourcePool:1222 –
com.mchange.v2.resou
rcepool.BasicResourcePool$AcquireTask@61f1680f
— Acquisition Attempt Failed!!! Clearing pending acquires. While
trying to acquire a needed new
resource, we fai led to succeed more
than the maximum number of allowed
acquisition attempts (30) .
[hibernatetool] 18:08:26,554 ERROR
SchemaExport:202 – schema export
unsuccessful[hibernatetool] java.sql.SQLException:
Connections could not be acquired from
th e underlying database!
[hibernatetool] at
com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.j
ava:104) [hibernatetool] at
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.che
ckoutPooledConnection(C3P0PooledConnectionPool.java:236)
[hibernatetool] at
com.mchange.v2.c3p0.PoolBackedDataSource.getConnectio
n(PoolBackedDataSource.java:94)
[hibernatetool] at
org.hibernate.connection.C3P0ConnectionProvider.getCo
nnection(C3P0ConnectionProvider.java:35)
[hibernatetool] at
org.hibernate.tool.hbm2ddl.ManagedProviderConnectionH
elper.prepare(ManagedProviderConnectionHelper.java:28)
[hibernatetool] at
org.hibernate.tool.hbm2ddl.SchemaExport.execute(Schem
aExport.java:180) [hibernatetool]
at
org.hibernate.tool.hbm2ddl.SchemaExport.create(Schema
Export.java:133) [hibernatetool]
at
org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hb
m2DDLExporterTask.java:55)
[hibernatetool] at
org.hibernate.tool.ant.HibernateToolTask.execute(Hibe
rnateToolTask.java:171)
[hibernatetool] at
org.apache.tools.ant.UnknownElement.execute(UnknownEl
ement.java:291) [hibernatetool]
at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native
M ethod) [hibernatetool] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMet
hodAccessorImpl.java:39)
[hibernatetool] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(Deleg
atingMethodAccessorImpl.java:25)
[hibernatetool] at
java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool] at
org.apache.tools.ant.dispatch.DispatchUtils.execute(D
ispatchUtils.java:106) [hibernatetool]
at
org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool] at
org.apache.tools.ant.Target.execute(Target.java:390)
[hibernatetool] at
org.apache.tools.ant.Target.performTasks(Target.java:
411) [hibernatetool] at
org.apache.tools.ant.Project.executeSortedTargets(Pro
ject.java:1397) [hibernatetool]
at
org.apache.tools.ant.Project.executeTarget(Project.ja
va:1366) [hibernatetool] at
org.apache.tools.ant.helper.DefaultExecutor.executeTa
rgets(DefaultExecutor.java:41)
[hibernatetool] at
org.apache.tools.ant.Project.executeTargets(Project.j
ava:1249) [hibernatetool] at
org.apache.tools.ant.Main.runBuild(Main.java:801)
[hibernatetool] at
org.apache.tools.ant.Main.startAnt(Main.java:218)
[hibernatetool] at
org.apache.tools.ant.launch.Launcher.run(Launcher.jav
a:280) [hibernatetool] at
org.apache.tools.ant.launch.Launcher.main(Launcher.ja
va:109) [hibernatetool] Caused by:
com.mchange.v2.resourcepool.CannotAcquireResourceExce
ption: A ResourcePool could not
acquire a resource from its primary
factory or s ource. [hibernatetool]
at
com.mchange.v2.resourcepool.BasicResourcePool.awaitAc
quire(BasicResourcePool.java:970)
[hibernatetool] at
com.mchange.v2.resourcepool.BasicResourcePool.checkou
tResource(BasicResourcePool.java:208)
[hibernatetool] at
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.che
ckoutPooledConnection(C3P0PooledConnectionPool.java:232)
[hibernatetool] … 24 more
[hibernatetool] 1 errors occurred
while performing .
[hibernatetool] Error #1:
java.sql.SQLException: Connections
could not be acquir ed from the
underlying database! [hibernatetool]
18:08:26,569 WARN
BasicResourcePool:1222 –
com.mchange.v2.resou
rcepool.BasicResourcePool$AcquireTask@72f864fe
— Acquisition Attempt Failed!!! Clearing pending acquires. While
trying to acquire a needed new
resource, we fai led to succeed more
than the maximum number of allowed
acquisition attempts (30) .`
I don’t have too much knowledge about either hiberate or HSQL..
Some one please explain whats wrong here??
Thanks
EDIT: I am trying to run the project helloworld-native.
The target given in the ant build.xml for startdb is as below:
<!-- Start the HSQL DB server -->
<target name="startdb" description="Run HSQL database server with clean DB">
<!-- Delete database files -->
<delete dir="${database.dir}"/>
<java classname="org.hsqldb.Server"
fork="yes"
classpathref="project.classpath"
failonerror="true">
<arg value="-database.0"/>
<arg value="file:${database.dir}/db"/>
</java>
</target>
and when i run the command ant startdb i see the below output:
startdb:
[delete] Deleting directory C:\Users\Ramesh\Desktop\Tutorials\hibernate\Hibernate Code samples\jpwh-gettingstarted-070401\helloworld-native\database
[java] [Server@15ded0fd]: [Thread[main,5,main]]: checkRunning(false) entered
[java] [Server@15ded0fd]: [Thread[main,5,main]]: checkRunning(false) exited
[java] [Server@15ded0fd]: Startup sequence initiated from main() method
[java] [Server@15ded0fd]: Loaded properties from [C:\Users\Ramesh\Desktop\Tutorials hibernate\Hibernate Code samples\jpwh-gettingstarted-070401\helloworld-native\server.properties]
[java] [Server@15ded0fd]: Initiating startup sequence...
[java] [Server@15ded0fd]: Server socket opened successfully in 29 ms.
[java] [Server@15ded0fd]: Database [index=0, id=0, db=file:database/db, alias=] opened sucessfully in 469 ms.
[java] [Server@15ded0fd]: Startup sequence completed in 523 ms.
[java] [Server@15ded0fd]: 2010-11-08 22:11:08.027 HSQLDB server 1.8.0 is online
[java] [Server@15ded0fd]: To close normally, connect and execute SHUTDOWN SQL
[java] [Server@15ded0fd]: From command line, use [Ctrl]+[C] to abort abruptly
Then, i think i am running HSQL DB in server mode only (from the above output)..
Please tell me what else I am missing..
Update: After a second look, it appears that I was wrong, you can start HSQL in server mode using the ant script and you’re not forced to use the command line. Actually, I tried to reproduce the problem with the
helloworld-nativesample but it worked fine for me.First, I started HSQLDB in a first shell using
ant startdb:Then, I ran
ant schemaexportfrom another shell:And indeed, when running
ant dbmanager, I can see theMESSAGEStable as expected.So everything worked just fine, out of the box. If it doesn’t for you, maybe start looking at things such as a networking issue, a personal firewall, etc.
According to the trace, it looks like HSQL is not started (at least not in server mode) and I suspect that you didn’t start it like you are supposed to. To start it in server mode, from the
helloworld-reversedirectory, run (as explained in the section Starting the HSQL database system, p 98):Then you’ll be able to connect to it using the
jdbc:hsqldb:hsql://localhostconnection string.