0

我使用 JPA 工具从@Entity类生成表。当设置为RESOURCE_LOCAL它工作得很好。但是,在我在 glassfish 服务器上设置数据源并进行persistence.xml相应修改后,它会停止并出现异常:

javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/mysqltest].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/mysqltest' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
...

因此,每次我想修改表结构时,我都需要将其改回

<persistence ...>
    <persistence-unit name="Foo" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/footest</jta-data-source>
        <properties>
            <property name="eclipselink.target-server" value="None"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
        </properties>
    </persistence-unit>
</persistence>

<persistence ...>
    <persistence-unit name="Foo" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/test"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="root"/>
            <property name="eclipselink.target-server" value="None"/>
            <property name="eclipselink.logging.level" value="FINEST"/>
        </properties>
    </persistence-unit>
</persistence>

有没有办法不用修改配置就可以使用表格生成工具?

4

1 回答 1

0

jta-data-source 名称是否有效?尝试完全限定 URL。

<jta-data-source>java:/jdbc/footest</jta-data-source>
于 2012-04-23T15:37:21.270 回答