Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为JPA Hibernate定义非JTA数据源?org.hibernate.connection.DatasourceConnectionProvider-找不到数据源:_Java_Hibernate_Orm_Jpa_Jpa 2.0 - Fatal编程技术网

Java 如何为JPA Hibernate定义非JTA数据源?org.hibernate.connection.DatasourceConnectionProvider-找不到数据源:

Java 如何为JPA Hibernate定义非JTA数据源?org.hibernate.connection.DatasourceConnectionProvider-找不到数据源:,java,hibernate,orm,jpa,jpa-2.0,Java,Hibernate,Orm,Jpa,Jpa 2.0,我正在尝试使用Hibernate作为提供程序将我的web应用程序的JDBC代码更改为JPA。我正在使用EclipseIDE。在这里,我定义了一个MySQL数据源。我在persistence.xml中添加了它。 但是,我得到了下面的错误 6640 [30289364@qtp-7494106-7] ERROR org.hibernate.connection.DatasourceConnectionProvider - Could not find datasource: tamSql javax

我正在尝试使用Hibernate作为提供程序将我的web应用程序的JDBC代码更改为JPA。我正在使用EclipseIDE。在这里,我定义了一个MySQL数据源。我在persistence.xml中添加了它。 但是,我得到了下面的错误

6640 [30289364@qtp-7494106-7] ERROR org.hibernate.connection.DatasourceConnectionProvider  - Could not find datasource: tamSql
javax.naming.NameNotFoundException; remaining name 'tamSql'
我的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="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>

org.hibernate.ejb.HibernatePersistence
塔姆SQL
com.pricar.JPAInteg.Role
com.pricar.JPAInteg.User
com.pricar.JPAInteg.Userdetail
com.pricar.JPAInteg.Category
com.pricar.JPAInteg.Expens
com.pricar.JPAInteg.Leavetable
com.pricar.JPAInteg.Permissiontoken
com.pricar.JPAInteg.roletoken协会
com.pricar.JPAInteg.UserPK

任何建议!!!
提前谢谢

中配置数据源时,不需要
<代码>是在应用程序服务器配置中配置数据源并通过JNDI获取数据源时需要的。

您可以发布您如何声明JNDI名称的代码。@Jaydeep:您可以告诉我JNDI名称是什么吗?我必须在哪里声明它。我对JPA和Hibernate非常陌生。谢谢,你说得对。谢谢你的回复。事实上,miss理解JPA/Hibernate规范。如果您告诉我“我应该使用事务类型scope=“RESOURCE\u LOCAL”吗?我将不胜感激。因为我只添加了。不同的事务类型和
/
//code>只有在您使用成熟的应用程序服务器(JBoss、WebSphere、WebLogic等)时才有意义。如果您有独立的应用程序或servlet容器(Tomcat,Jetty),您只需编写
transaction type=“RESOURCE\u LOCAL”
。是否有一种方法可以在eclipse或windows机器中进行配置,这样我就不需要为本地/服务器使用多个持久化单元