2011-04-20 2 views
1

EJB3.0 컨테이너 관리 영속성 bean을 생성하려고 시도하고 있으며 단위 테스트에서 사용되는 메모리 내 HSQLDB에 연결하는 데 문제가 있습니다. 독립 실행 형 컨테이너 구현을 위해 OpenEJB를 사용하고 있습니다.HSQLDB EJB3.0 Hibernate가 DB에 연결할 수 없음

다음과 같이 내 영속성 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> 

그리고 이것은 내 서비스 콩입니다 : 이것은 내 단위 테스트입니다

@Stateless 
public class LogEntryServiceBean implements LogEntryService { 

@PersistenceContext 
private EntityManager entityManager; 

@Override 
public LogEntry find(String uuid) { 
    return entityManager.find(LogEntry.class, uuid); 
} 

@Override 
public void save(LogEntry logEntry) { 
    entityManager.merge(logEntry); 
} 

@Override 
public void remove(LogEntry logEntry) { 
    entityManager.remove(entityManager.merge(logEntry)); // NOTE: [MF] Using "seek and destroy" pattern. 
} 
} 

:

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("[email protected]"); 
    logEntry.getAddressees().add(addressee); 
    logEntryService.save(logEntry); 
} 

} 

내 단위 테스트를 실행하면 나는 다음과 같은 오류 얻을 :

java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.

내가 뭘 잘못하고 있는지에 대한 아이디어 (또는하지 않는 것) 전혀)?

감사합니다.

답변

1

저는 바보입니다. 나는 in-VM OpenEJB 임베디드 컨테이너 대신 GlassFish 라이브러리를 사용하는 EJB3.0 임베디드 컨테이너를 시작했습니다.

@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 나는 다음과 같이 제의 persistence.xml 지속성 - 단위를 지정하는 데 필요한 비 JTA 데이터 소스가 becuase :이다

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