我使用 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>
有没有办法不用修改配置就可以使用表格生成工具?