java 与 HSQLDB 的休眠连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11540758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 05:30:05  来源:igfitidea点击:

Hibernate connection with HSQLDB

javahibernatejdbchsqldb

提问by user1534610

I have a problem while setting up my first Hibernate project. I follow the tutorial and get stuck when I launch my code. What happens is that the program get stuck, I believe, when starting the connection with HSQLDB. It does not provide any error message.
The verbose output in the console is the following:

我在设置我的第一个 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

now it is configured, I call buildSessionFactory():

现在它已配置,我调用 buildSessionFactory():

562 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: org.itg.ACLwithHibernate.User -> USER
577 [main] INFO org.hibernate.cfg.Configuration - Hibernate Validator not found: ignoring
593 [main] INFO org.hibernate.cfg.search.HibernateSearchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
593 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
593 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 10
593 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
609 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost:9001
609 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}

and... nothing more. It never goes on to the next instructions in my main() class. It is stuck somewhere. When I debug, I get this:

还有……仅此而已。它永远不会继续执行我的 main() 类中的下一条指令。它被卡在某个地方。当我调试时,我得到这个:

overview of the debugger

调试器概述

Here is my hibernate.cfg.xml:

这是我的 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>

My HSQLDB server is running and outputed the following:

我的 HSQLDB 服务器正在运行并输出以下内容:

[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

When server.silent = false, I get in addition the following when my client connects:

当 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

Have you encountered a similar issue before? Do you have an idea about what is going wrong?
Thank you very much in advance.
Dany

你以前遇到过类似的问题吗?你知道出了什么问题吗?
非常感谢您提前。
丹妮

回答by fredt

When an HSQLDB Server is used with Hibernate or other frameworks, it is essential to check the HSQLDB jar version used by the client and server and make sure they are both the same version of HSQLDB. It is also necessary to use an up-to-date version of HSQLDB.

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

It is easy to troubleshoot an HSQLDB Server if you start it with the property server.silent=false(or silent=falseas a command line argument). This will show the attempted connections.

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

In this example, the server is showing:

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

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

which indicates a version incompatibility problem, as the ODBC is not actually used for Java to HSQLDB connections.

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

回答by Avihai Marchiano

It stuck in connecting to your DB. for debugging remove the connection pool size element from the configuration and set hbmtoddl to false.

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