6

context.xml我在Tomcat中有以下代码:

<Resource name="ds/OracleDS" auth="Container" type="javax.sql.DataSource"
maxActive="1" maxIdle="2" maxWait="2"
username="demo" password="demo"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl"/>

我有这个代码web.xml

<resource-ref>
 <description>Oracle Datasource example</description>
 <res-ref-name>ds/OracleDS</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>

我已经编写了persistence.xml如下代码:

<persistence-unit name="ReceivablesPU"  transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <non-jta-data-source>java:ds/OracleDS</non-jta-data-source>

我不明白java:ds/OracleDS,,,<Resource name="ds/OracleDS"<res-ref-name>ds/OracleDS</res-ref-name>错误是:

javax.persistence.PersistenceException: Exception [TOPLINK-7060] (Oracle TopLink Essentials - 2.0 (Build b40-rc (03/21/2007))): oracle.toplink.essentials.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:ds/OracleDS].
Internal Exception: javax.naming.NamingException: This context must be accessed through a java: URL
4

3 回答 3

2

persistence.xml中,您的第三行应如下所示:

        <non-jta-data-source>java:comp/env/ds/OracleDS</non-jta-data-source>
于 2013-03-14T15:31:56.810 回答
1

我在 contex.xml 中的变化:

<Resource name="OracleDS" auth="Container" type="javax.sql.DataSource"
    maxActive="1" maxIdle="2" maxWait="2"
    username="demo" password="demo"
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@localhost:1521:orcl"/>

我在 web.xml 中的变化:

<resource-ref>
     <description>Oracle Datasource example</description>
     <res-ref-name>OracleDS</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
    </resource-ref>

我更改persistence.xml

<persistence-unit name="ReceivablesPU"  transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/OracleDS</non-jta-data-source>

然后我得到了输出....

于 2013-03-16T05:24:38.937 回答
0

请参阅类似(但不是重复问题)的答案:

码头数据源,休眠,未找到数据源

根据 Java EE Web App 容器,对于名为“ds/OracleDS”的数据源,您可能需要在寻址时为其 JNDI 上下文添加前缀“java:comp/env”(例如,在您的 persistence.xml 文件中)以使其工作。

在您的 Tomcat 的特定情况下,我会尝试以下操作:

<Resource name="ds/OracleDS" auth="Container" type="javax.sql.DataSource"
maxActive="1" maxIdle="2" maxWait="2"
username="demo" password="demo"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl"/>

您的 web.xml 中不需要任何内容​​。context.xml 中的上述配置将使 Tomcat 将数据源公开为 JNDI 资源

最后,在 persistence.xml 中放:

<persistence-unit name="ReceivablesPU"  transaction-type="RESOURCE_LOCAL">
        <provider>oracle.toplink.essentials.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/ds/OracleDS</non-jta-data-source>
于 2013-03-22T15:52:04.377 回答