不确切知道jta-data-source应该是什么

时间:2014-08-23 09:24:36

标签: java spring hibernate tomcat jta

我尝试使用Postgres服务器获得Spring-MVC,Hibernate,JTA。

我得到了大部分工作(从Db通过没有JTA的EntityManager读取),但我无法让事务与JTA一起工作。

<?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="defaultPersistenceUnit" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>???</jta-data-source>
    <class>net.test.test.database.UsersEntity</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/mydb" />
        <property name="javax.persistence.jdbc.user" value="postgres"/>
        <property name="javax.persistence.jdbc.password" value="validpw"/>
    </properties>
</persistence-unit>

如果我从servlet提供我的数据源,我会得到一个像

这样的异常
DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'dataSource'

我还发现资源说应该在应用程序服务器中定义数据源(但我不确定这个)。如果重要的话我使用Tomcat服务器。

0 个答案:

没有答案