1
我在曼寧閱讀EJB 3,第二版中間時遇到運行源測試中的IntelliJ如何與Hibernate
測試一個艱難的時間與運行的Arquillian IN_CONTAINER模式測試是: 全部源代碼,可以發現here:
@RunWith(Arquillian.class)
@Run(RunModeType.IN_CONTAINER)
....
.....
@Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "foo.jar").addClasses(OrderProcessor.class,
OrderProcessorBean.class,
ItemService.class,
ItemServiceBean.class, Bid.class, Bidder.class, Item.class).addManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
}
的persistence.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="users" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/chapter2</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
</properties>
</persistence-unit>
</persistence>
錯誤,同時運行測試:
WARNING: Could not obtain connection to query metadata
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.
at com.sun.gjc.spi.base.DataSource.getConnection(DataSource.java:112)
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71)
UPDATE
domain.xml中位於here:
從它看起來像一個數據庫連接不能建立的錯誤。但是,我不確定爲什麼它無法連接到內存德比數據庫。由於domain.xml具有create=true
屬性,所以應該簡單地創建數據庫。
謝謝,這清除了事情。但是我仍然無法看到'domain.xml',即使添加了命名空間,我也會得到相同的錯誤。 – Omnipresent