Hibernate2连Hsqldb的问题Connection is broken

今天写Testcase时,用Hibernate连Hsqldb,出现异常Connection is broken: Transfer corrupted, SQL Error: -3, SQLState: 08003

 

代码:

Configuration configuration = new Configuration()
.addClass(Book.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect")
.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver")

.setProperty("hibernate.connection.url", "jdbc:hsqldb:file:data/testdb")

//.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:testdb")
//.setProperty("hibernate.connection.url", "jdbc:hsqldb:hsql://localhost/testdb")
//.setProperty("hibernate.connection.username", "sa")
//.setProperty("hibernate.connection.password", "");


SessionFactory factory = configuration.buildSessionFactory();

 

当hsqldb数据源为file或mem方式时,一切正常,如果换成以server方式,以jdbc:hsqldb:hsql://localhost/testdb,就报:

00:25:05,625  WARN SettingsFactory:107 - Could not obtain connection metadata
java.sql.SQLException: Connection is broken: Transfer corrupted
 at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
 at org.hsqldb.jdbc.jdbcConnection.getAutoCommit(Unknown Source)
 at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:103)
 at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
 at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1172)
 at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:803)
 at CatTest.setUp(CatTest.java:14)
 at junit.framework.TestCase.runBare(TestCase.java:125)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at junit.textui.TestRunner.doRun(TestRunner.java:116)
 at com.intellij.rt.execution.junit.IdeaTestRunner.doRun(IdeaTestRunner.java:65)
 at junit.textui.TestRunner.doRun(TestRunner.java:109)
 at com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs(IdeaTestRunner.java:24)
 at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:118)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
00:25:07,562  WARN JDBCExceptionReporter:57 - SQL Error: -3, SQLState: 08003
00:25:07,562 ERROR JDBCExceptionReporter:58 - Connection is broken: Transfer corrupted

net.sf.hibernate.exception.GenericJDBCException: Cannot open connection
 at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)
 at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)
 at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
 at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:328)
 at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:295)
 at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3373)
 at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3333)
 at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
 at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
 at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2252)
 at CatTest.setUp(CatTest.java:15)
 at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
Caused by: java.sql.SQLException: Connection is broken: Transfer corrupted
 at org.hsqldb.jdbc.jdbcUtil.sqlException(Unknown Source)
 at org.hsqldb.jdbc.jdbcConnection.getAutoCommit(Unknown Source)
 at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:103)
 at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:292)
 ... 17 more

最好发现是server端和testcase客户端的hsqldb.jar的版本不一致所导致,两边的jar包统一后解决

你可能感兴趣的:(java,Hibernate,.net,JUnit,HSQLDB)