2010-11-07 148 views
3

我想通過Gavin King的Java Persistence與Hibernate學習Hibernate。無法從底層數據庫獲取連接! - HSQL DB

我剛剛下載從這個位置http://downloads.jboss.org/hibernate/caveatemptor/jpwh-gettingstarted-070401.zip

書中給出的例子,我開始我的HSQL DB使用螞蟻startdb和數據庫成功啓動。

當試圖運行目標的SchemaExport我收到以下錯誤..

SchemaExport工具:[hibernatetool] 執行的Hibernate工具與 標準配置[hibernatetool] 1.任務:就是hbm2ddl(生成數據庫模式)[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信息 環境:667 - 字節碼提供呃 名稱:CG LIB [hibernatetool] 18:07:56571信息環境:584 - 使用JDK 1.4的java.sql.Time郵票 處理[hibernatetool] 18:07:56617 信息配置:1384 - 從文件中配置 :H ibernate.cfg.xml [hibernatetool] 18:07:56680 INFO 配置:507 - 讀映射 從RES烏爾斯河:你好/ Message.hbm.xml [hibernatetool] 18:07:56758 INFO HbmBinder:300 - 映射類: hello.Message - > MESSAGES [hibernatetool] 18:07:56,851信息配置:1465 - 配置的SessionFactor y:null [hibernatetool] 18:07:56,851信息 方言:141 - 使用方言: org.hibernate.di alect.HSQLDialect [hibernatetool] 18:07:56914 INFO SchemaExport工具:154 - 運行就是hbm2ddl 架構EXP ORT [hibernatetool] 18:07:56914 INFO SchemaExport工具: 174 - 寫入生成的模式到文件: C:\用戶\拉梅什\桌面\教程\休眠\休眠 代碼樣本\ jpwh- gettingstarted-070401 \ HelloWorld的天然\的HelloWorld-ddl.sql [hibernatetool] 18: 07:56,914 INFO SchemaExport:179 - 導出生成 模式到數據庫[hibernatetool] 18:07:56,914信息 C3P0ConnectionProvider:50 - C3P0使用 驅動程序:在org.hsqldb.jdbcDriver URL: JDBC:HSQLDB:HSQL://本地主機 [hibernatetool] 18:07:56914 INFO C3P0ConnectionProvider:51 - 連接 正確關係:{用戶= SA} [hibernatetool] 18:07:56914 INFO C3P0ConnectionProvider:54 - 自動提交 模式:假[hibernatetool] 18:08:26554 WARN BasicResourcePool:1222 - com.mchange.v2.resou [email protected] - 收購嘗試失敗!清理未完成的採集。儘管 試圖獲取所需的新資源 資源,但我們仍然獲得了比最大允許獲取次數 (30)更多的 。 [hibernatetool] 18:08:26554 ERROR SchemaExport工具:202 - 架構出口 不成功

[hibernatetool]值java.sql.SQLException: 連接無法從 前作基礎數據庫獲取! [hibernatetool]在 com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.j AVA:104)[hibernatetool]在 com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.che ckoutPooledConnection(C3P0PooledConnectionPool.java :236) [hibernatetool]在 com.mchange.v2.c3p0.PoolBackedDataSource.getConnectio N(PoolBackedDataSource.java:94) 在[hibernatetool] org.hibernate.connection.C3P0ConnectionProvider.getCo nnection(C3P0ConnectionProvider.java :35) [hibernatetool] at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionH elper.prepare(ManagedProviderConnectio nHelper.java:28) [hibernatetool]在 org.hibernate.tool.hbm2ddl.SchemaExport.execute(舍姆 aExport.java:180)[hibernatetool]
在 org.hibernate.tool.hbm2ddl.SchemaExport.create (模式 Export.java:133)[hibernatetool]
在 org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(血紅蛋白 m2DDLExporterTask.java:55) 在 org.hibernate.tool.ant [hibernatetool]。 HibernateToolTask​​.execute(Hibe rnateToolTask​​.java:171) [hibernatetool] at org.apache.tools.ant.UnknownElement.execute(UnknownEl ement.java:291)[hibernatetool]
在 sun.reflect.NativeMethodAccessorImpl.invoke0(母語 中號ethod)[hibernatetool]在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMet hodAccessorImpl.java:39) [ hibernatetool]在 sun.reflect.DelegatingMethodAccessorImpl.invoke(德勒 atingMethodAccessorImpl.java:25) [hibernatetool]在 java.lang.reflect.Method.invoke(Method.java:597) [hibernatetool]在 有機apache.tools.ant.dispatch.DispatchUtils.execute(D ispatchUtils.java:106)[hibernatetool] at org.apache.tools.ant.Task.perform(Task.java:348) [hibernatetool]在 org.apache.tools.ant.Target.execute(Target.java:390) [hibernatetool]在 有機.apache.tools.ant.Target.performTasks(Target.java: 411)[hibernatetool]在 org.apache.tools.ant.Project.executeSortedTargets(臨 ject.java:1397)[hibernatetool]
在 org.apache.tools.ant.Project.executeTarget(Project.ja VA:1366)[hibernatetool]在 org.apache.tools.ant.helper.DefaultExecutor.executeTa rgets(DefaultExecutor.java:41) [hibernatetool ]在 org.apac he.tools.ant.Project.executeTargets(Project.j AVA:1249)[hibernatetool]在 org.apache.tools.ant.Main.runBuild(Main.java:801) [hibernatetool]在 org.apache .tools.ant.Main.startAnt(Main.java:218) [hibernatetool] at org.apache.tools.ant.launch.Launcher.run(Launcher。JAV 一個:280)[hibernatetool]在 org.apache.tools.ant.launch.Launcher.main(Launcher.ja VA:109)[hibernatetool]所致: com.mchange.v2.resourcepool.CannotAcquireResourceExce ption:一個ResourcePool不能從 工廠或工廠獲取資源 。 [hibernatetool]
在 com.mchange.v2.resourcepool.BasicResourcePool.awaitAc 疊紙(BasicResourcePool.java:970) [hibernatetool]在 com.mchange.v2.resourcepool.BasicResourcePool.checkou tResource(BasicResourcePool.java :208) [hibernatetool]在 com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.che ckoutPooledConnection(C3P0PooledConnectionPool.java:232) [hibernatetool] ...同時執行時發生24更 [hibernatetool] 1個錯誤 。 [hibernatetool]錯誤#1: java.sql.SQLException:連接 無法從 底層數據庫中獲得! [hibernatetool] 18:08:26569 WARN BasicResourcePool:1222 - com.mchange.v2.resou [email protected] - 採集嘗試失敗!!!清理未完成的採集。雖然 試圖獲取所需的新 的資源,我們的固定資產投資導致成功超過允許 獲取嘗試(30)的最大數量.`

更 我沒有關於任何hiberate或太多的知識HSQL ..

有人請說明這裏有什麼錯?

感謝

編輯:我試圖運行項目helloworld-native

在startdb螞蟻的build.xml給出的目標是如下:

<!-- 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> 

,當我運行命令ant startdb我看到下面的輸出:

startdb: 
    [delete] Deleting directory C:\Users\Ramesh\Desktop\Tutorials\hibernate\Hibernate Code samples\jpwh-gettingstarted-070401\helloworld-native\database 
    [java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered 
    [java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited 

    [java] [[email protected]]: Startup sequence initiated from main() method 
    [java] [[email protected]]: Loaded properties from [C:\Users\Ramesh\Desktop\Tutorials hibernate\Hibernate Code samples\jpwh-gettingstarted-070401\helloworld-native\server.properties] 
    [java] [[email protected]]: Initiating startup sequence... 
    [java] [[email protected]]: Server socket opened successfully in 29 ms. 
    [java] [[email protected]]: Database [index=0, id=0, db=file:database/db, alias=] opened sucessfully in 469 ms. 
    [java] [[email protected]]: Startup sequence completed in 523 ms. 
    [java] [[email protected]]: 2010-11-08 22:11:08.027 HSQLDB server 1.8.0 is online 
    [java] [[email protected]]: To close normally, connect and execute SHUTDOWN SQL 
    [java] [[email protected]]: From command line, use [Ctrl]+[C] to abort abruptly 

然後,我想我只在服務器模式下運行HSQL DB(從上面的輸出)..

請告訴我還有什麼我丟失..

+0

嘗試與MySQL..and它工作..不知道什麼是probelm? – javanoob 2010-11-07 13:23:19

回答

1

更新:經過第二次查看,看起來我錯了,您可以使用ant腳本在服務器模式下啓動HSQL,並且您不必使用命令行。其實,我試圖重現與helloworld-native樣品的問題,但它對我來說工作得很好。

首先,我在第一外殼採用ant startdb開始HSQLDB:

$ ant startdb 
Buildfile: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml 

startdb: 
    [java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) entered 
    [java] [[email protected]]: [Thread[main,5,main]]: checkRunning(false) exited 
    [java] [[email protected]]: Startup sequence initiated from main() method 
    [java] [[email protected]]: Loaded properties from [/home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/server.properties] 
    [java] [[email protected]]: Initiating startup sequence... 
    [java] [[email protected]]: Server socket opened successfully in 39 ms. 
    [java] [[email protected]]: Database [index=0, id=0, db=file:database/db, alias=] opened sucessfully in 1148 ms. 
    [java] [[email protected]]: Startup sequence completed in 1281 ms. 
    [java] [[email protected]]: 2010-11-08 18:29:20.094 HSQLDB server 1.8.0 is online 
    [java] [[email protected]]: To close normally, connect and execute SHUTDOWN SQL 
    [java] [[email protected]]: From command line, use [Ctrl]+[C] to abort abruptly 

然後,我從另一個shell跑ant schemaexport

$ ant schemaexport 
Buildfile: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml 

compile: 
    [mkdir] Created dir: /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build 
    [javac] /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build.xml:39: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds 
    [javac] Compiling 3 source files to /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build 

copymetafiles: 
    [copy] Copying 3 files to /home/pascal/Projects/jpwh-gettingstarted-070401/helloworld-native/build 

schemaexport: 
[hibernatetool] Executing Hibernate Tool with a Standard Configuration 
[hibernatetool] 1. task: hbm2ddl (Generates database schema) 
[hibernatetool] 
[hibernatetool]  alter table MESSAGES 
[hibernatetool]   drop constraint FK_NEXT_MESSAGE; 
[hibernatetool] 
[hibernatetool]  drop table MESSAGES if exists; 
[hibernatetool] 
[hibernatetool]  create table MESSAGES (
[hibernatetool]   MESSAGE_ID bigint generated by default as identity (start with 1), 
[hibernatetool]   MESSAGE_TEXT varchar(255), 
[hibernatetool]   NEXT_MESSAGE_ID bigint, 
[hibernatetool]   primary key (MESSAGE_ID) 
[hibernatetool] ); 
[hibernatetool] 
[hibernatetool]  alter table MESSAGES 
[hibernatetool]   add constraint FK_NEXT_MESSAGE 
[hibernatetool]   foreign key (NEXT_MESSAGE_ID) 
[hibernatetool]   references MESSAGES; 
[hibernatetool] 1 errors occurred while performing <hbm2ddl>. 
[hibernatetool] Error #1: java.sql.SQLException: Table not found: MESSAGES in statement [alter table MESSAGES] 

BUILD SUCCESSFUL 
Total time: 14 seconds 

事實上,運行ant dbmanager的時候,我可以看到MESSAGES表如預期。

所以一切正常,開箱即用。如果它不適合你,也許開始看的東西,如一個網絡問題,個人防火牆等


據跟蹤,它看起來像HSQL未啓動(至少不是在服務器模式),我懷疑你沒有像你應該做的那樣開始。以服務器模式啓動,從helloworld-reverse目錄,運行(如第啓動HSQL數據庫系統解釋說,第98頁):

$ java -cp lib/hsqldb.jar org.hsqldb.Server 

然後你就可以連接使用它來連接字符串爲jdbc:hsqldb:hsql://localhost

+0

帕斯卡爾,感謝您的時間和意見.. – javanoob 2010-11-08 16:42:27

+0

帕斯卡爾,我對問題添加了意見...你可以看看你什麼時候有空..預先感謝.. – javanoob 2010-11-08 17:02:45

+0

感謝帕斯卡爾..讓我看看我的問題...正如你所說我認爲這個問題可能與網絡..但是,我可以繼續'MySql'數據庫。再次感謝 – javanoob 2010-11-09 03:43:35