Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HSQLDB EJB3.0 Hibernate无法连接到数据库_Hibernate_Ejb_Hsqldb_Persistence.xml - Fatal编程技术网

HSQLDB EJB3.0 Hibernate无法连接到数据库

HSQLDB EJB3.0 Hibernate无法连接到数据库,hibernate,ejb,hsqldb,persistence.xml,Hibernate,Ejb,Hsqldb,Persistence.xml,我正在尝试创建一个EJB3.0容器管理的持久性bean,但在连接到单元测试使用的内存中HSQLDB时遇到问题。我将OpenEJB用于我的独立容器实现 我的持久性XML中有以下内容 <persistence-unit name="wyvern-unit-test"> <description>In-memory HSQLDB database persistence unit used for unit testing.</description>

我正在尝试创建一个EJB3.0容器管理的持久性bean,但在连接到单元测试使用的内存中HSQLDB时遇到问题。我将OpenEJB用于我的独立容器实现

我的持久性XML中有以下内容

    <persistence-unit name="wyvern-unit-test">
    <description>In-memory HSQLDB database persistence unit used for unit testing.</description>
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.acme.test.model.LogEntry</class>
    <class>com.acme.test.modell.Addressee</class>
    <properties>
        <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
        <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:db"/>
        <property name="hibernate.connection.username" value="sa"/>
        <property name="hibernate.connection.password" value=""/>
        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
    </properties>
</persistence-unit>
这是我的单元测试:

public class LogEntryServiceBeanTest {

private static Context context;

@BeforeClass
public static void beforeClass() {
    context = EJBContainer.createEJBContainer().getContext();
}

@AfterClass
public static void afterClass() throws NamingException {
    context.close();
}

@Test
public void createLogEntryTest() throws NamingException {
    LogEntryService logEntryService = (LogEntryService) context.lookup("java:global/classes/LogEntryServiceBean");
    LogEntry logEntry = new LogEntry();
    Addressee addressee = new Addressee();
    logEntry.setSummary("This is a log entry.");
    addressee.setName("John Smith");
    addressee.setEmailAddress("john.smith@acme.com.au");
    logEntry.getAddressees().add(addressee);
    logEntryService.save(logEntry);
}

}
当我运行单元测试时,出现以下错误:

java.sql.SQLException:分配连接时出错。原因:无法分配连接,因为:java.net.ConnectException:连接到端口1527上的服务器本地主机时出错,消息连接被拒绝

关于我做错了什么(或根本没有做)有什么想法吗


谢谢,我是个白痴。我正在启动EJB3.0嵌入式容器,它在VM OpenEJB嵌入式容器中使用GlassFish库

即:

@BeforeClass
public static void beforeClass() {
   context = EJBContainer.createEJBContainer().getContext();
}
应该是:

@BeforeClass
public static void beforeClass() {
    Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
    context = new InitialContext(properties);
}
此外,由于HSQLDB是一个非JTA数据源,我需要指定persistence.xml持久化单元,如下所示:

<persistence-unit name="wyvern-unit" transaction-type="RESOURCE_LOCAL">

我是个白痴。我正在启动EJB3.0嵌入式容器,它在VM OpenEJB嵌入式容器中使用GlassFish库

即:

@BeforeClass
public static void beforeClass() {
   context = EJBContainer.createEJBContainer().getContext();
}
应该是:

@BeforeClass
public static void beforeClass() {
    Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
    context = new InitialContext(properties);
}
此外,由于HSQLDB是一个非JTA数据源,我需要指定persistence.xml持久化单元,如下所示:

<persistence-unit name="wyvern-unit" transaction-type="RESOURCE_LOCAL">