当我试图获得一个Entitymanager时,我总是变成一个NamingException ..这就是它崩溃的地方:(在查找函数中)
try {
ctx = new InitialContext();
entityManager = (EntityManager)ctx.lookup("java:/comp/env/myExample");
} catch (NamingException namingException) {
throw new NamingException();
}
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="myExample">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>DSLDB</jta-data-source>
<mapping-file>META-INF/interface_orm.xml</mapping-file>
<properties>
<property name="openjpa.jdbc.UpdateManager" value="operation-order" />
<property name="openjpa.FlushBeforeQueries" value="false" />
<property name="openjpa.OrphanedKeyAction" value="none" />
<property name="openjpa.ConnectionRetainMode" value="transaction" />
<property name="openjpa.jdbc.DBDictionary" value="useNativeSequenceCache=true" />
</properties>
</persistence-unit>
</persistence>
persistence.xml位于META-INF文件夹中的lib组件下。
我还在deploy.xml中定义了数据源:
<datasource database="oracle">
<jndi_id value="DSLDB"/>
<user value="user"/>
<!-- <user value="user1"/> -->
<password value="password"/>
<jdbc_url value="jdbc:oracle:thin:@//skjdfhsdhf2009-skip.moage.org:1522/WKFISAS.nittaschoa.net"/> <!-- JAP7 IT -->
<transaction_protocol value="EmulateTwoPhaseCommit" />
<!--
<driver_class value="oracle.jdbc.OracleDriver" />
<support_xa_transaction value="true" />
<transaction_protocol value="None" />
<test_table value=" SQL SELECT 1 FROM DUAL" />
-->
</datasource>