Java Hibernate与HSQLDB的连接

Java Hibernate与HSQLDB的连接,java,hibernate,jdbc,hsqldb,Java,Hibernate,Jdbc,Hsqldb,我在设置第一个Hibernate项目时遇到问题。我遵循教程,在启动代码时陷入困境。我相信,当启动与HSQLDB的连接时,程序会被卡住。它不提供任何错误消息。 控制台中的详细输出如下所示: 172 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final 172 [main] INFO org.hibernate.cfg.Environment - Hiberna

我在设置第一个Hibernate项目时遇到问题。我遵循教程,在启动代码时陷入困境。我相信,当启动与HSQLDB的连接时,程序会被卡住。它不提供任何错误消息。
控制台中的详细输出如下所示:

172 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
172 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.10.Final
172 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
187 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
187 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
265 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
265 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
375 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : org/itg/ACLwithHibernate/User.hbm.xml
484 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
[Server@3ed5dee4]: [Thread[org.hsqldb.Server.main(),5,org.hsqldb.Server]]: checkRunning(false) entered
[Server@3ed5dee4]: [Thread[org.hsqldb.Server.main(),5,org.hsqldb.Server]]: checkRunning(false) exited
[Server@3ed5dee4]: Startup sequence initiated from main() method
[Server@3ed5dee4]: Loaded properties from [C:\Users\dbr\workspace\test_hibernate\server.properties]
[Server@3ed5dee4]: Initiating startup sequence...
[Server@3ed5dee4]: Server socket opened successfully in 0 ms.
[Server@3ed5dee4]: Database [index=0, id=0, db=file:target/data/tutorial, alias=] opened sucessfully in 630 ms.
[Server@3ed5dee4]: Startup sequence completed in 640 ms.
[Server@3ed5dee4]: 2012-07-18 12:36:53.717 HSQLDB server 2.0.0 is online on port 9001
[Server@3ed5dee4]: To close normally, connect and execute SHUTDOWN SQL
[Server@3ed5dee4]: From command line, use [Ctrl]+[C] to abort abruptly
现在配置好了,我调用buildSessionFactory()

而且。。。没别的了。在我的main()类中,它从不继续执行下一个指令。它卡在什么地方了。 调试时,我得到以下结果:

这是我的hibernate.cfg.xml:

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="connection.url">jdbc:hsqldb:hsql://localhost:9001</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">10</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.HSQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>

        <mapping resource="org/itg/ACLwithHibernate/User.hbm.xml"/>

    </session-factory>

</hibernate-configuration>
当server.silent=false时,当客户端连接时,我还会得到以下信息:

[Thread[HSQLDB Server @1af5458a,5,org.hsqldb.Server]]: handleConnection(Socket[addr=/127.0.0.1,port=49438,localport=9001]) entered
[Thread[HSQLDB Server @1af5458a,5,org.hsqldb.Server]]: handleConnection() exited
[Thread[HSQLDB Connection @9437a04,5,HSQLDB Connections @1af5458a]]: ODBC client connected.  ODBC Protocol Compatibility Version 0.0
您以前遇到过类似的问题吗?你知道哪里出了问题吗?
事先非常感谢。

Dany

它无法连接到您的数据库。
为了进行调试,请从配置中删除连接池大小元素,并将hbmtoddl设置为false。

当HSQLDB服务器与Hibernate或其他框架一起使用时,必须检查客户端和服务器使用的HSQLDB jar版本,并确保它们都是HSQLDB的相同版本。还需要使用最新版本的HSQLDB

如果使用属性
Server.silent=false
(或作为命令行参数的
silent=false
)启动HSQLDB服务器,则很容易对其进行故障排除。这将显示尝试的连接

在此示例中,服务器显示:

[Thread[HSQLDB Connection @9437a04,5,HSQLDB Connections @1af5458a]]: 
      ODBC client connected.  ODBC Protocol Compatibility Version 0.0

这表明存在版本不兼容问题,因为ODBC实际上不用于Java到HSQLDB的连接。

您的数据库是否在本地主机上运行?你能远程登录到localhost:9001吗?@Funtik你说得对,我没想过要试试。是的,我可以telnet,我可以得到
hsqldbjdbc网络监听器。具有网络兼容性版本1.9.0.0和JDBC URL(如JDBC:hsqldb:hsql://hostname...
然后断开连接。我不熟悉HSQLDB,但我会尝试创建一个数据库别名,并将其用作hibernate connection中的DB名称。调试时,将server.silent=false添加到server.properties。尝试使用HSQLDB2.2.8(来自Maven),因为这与Hibernate方言更兼容。谢谢@fredt,我尝试了版本2.2.8&server.silent=false,我编辑了我的帖子以包含固有的日志。不幸的是,它给了我非常相同的行为和输出。不知何故,连接似乎建立得很好,因为当我终止“冻结”代码时,我在服务器的输出端得到了一个
java.net.SocketException:connection reset
。我有
log4j.logger.org.hibernate=debug
log4j.rootLogger=debug,在我的log4j.properties中,stdout
log4j.logger.org.hibernate.SQL=debug
。但是您在信息模式下运行,而不是在调试模式下运行。您可以看到日志级别是info
[Thread[HSQLDB Connection @9437a04,5,HSQLDB Connections @1af5458a]]: 
      ODBC client connected.  ODBC Protocol Compatibility Version 0.0