如何为JPA-Hibernate定义非JTA数据源? org.hibernate.connection.DatasourceConnectionProvider - 无法找到数据源: [英] How to define an non-JTA datasource for JPA-Hibernate? org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource:

查看:209
本文介绍了如何为JPA-Hibernate定义非JTA数据源? org.hibernate.connection.DatasourceConnectionProvider - 无法找到数据源:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试将使用Hibernate作为提供者的Web应用程序的JDBC代码更改为JPA。我正在使用Eclipse IDE。在那里我定义了一个MySQL数据源。我将它添加到persistence.xml中。
但是,我收到了以下错误消息。

I am trying to change my web-app's JDBC code to JPA using Hibernate as provider. I am using Eclipse IDE. In that i have defined a MySQL data source. I added it in the persistence.xml. But, I am getting the below error.

6640 [30289364@qtp-7494106-7] ERROR org.hibernate.connection.DatasourceConnectionProvider  - Could not find datasource: tamSql
javax.naming.NameNotFoundException; remaining name 'tamSql'

我的persistence.xml看起来像 p>

My persistence.xml looks like,

<?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="ExpensePersistentUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>tamSql</non-jta-data-source>
    <class>com.pricar.JPAInteg.Role</class>
    <class>com.pricar.JPAInteg.User</class>
    <class>com.pricar.JPAInteg.Userdetail</class>
    <class>com.pricar.JPAInteg.Category</class>
    <class>com.pricar.JPAInteg.Expens</class>
    <class>com.pricar.JPAInteg.Leavetable</class>
    <class>com.pricar.JPAInteg.Permissiontoken</class>
    <class>com.pricar.JPAInteg.Roletokenassociation</class>
    <class>com.pricar.JPAInteg.UserPK</class>
<properties>
    <property name="hibernate.connection.url" value="jdbc:mysql://localhost/officemgmt"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
    <property name="hibernate.connection.password" value="1234"/>
    <property name="hibernate.connection.username" value="root"/>
    <property name="hibernate.hbm2ddl.auto" value="update"/>
    <property name="hibernate.show_sql" value="true"/>

</properties>





在此先感谢!

Any Suggestions!!! Thanks in Advance!

推荐答案

您不需要< non-jta-数据源> 当你的数据源在< properties> 中配置时。当数据源在应用程序服务器配置中配置并通过JNDI获取时,需要< non-jta-data-source>

You don't need <non-jta-data-source> when your datasource is configured in <properties>. <non-jta-data-source> is needed when datasource is configured in application server configuration and obtained via JNDI.

这篇关于如何为JPA-Hibernate定义非JTA数据源? org.hibernate.connection.DatasourceConnectionProvider - 无法找到数据源:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆