无法使用eclipse和eclipselink生成表格形式实体

时间:2014-04-28 21:34:32

标签: java eclipse jpa eclipselink

我尝试使用我的实体生成数据库结构。为此,我使用Eclipse工具。我是开普勒版本,但我也用juno测试过。

  

“右键单击项目 - > JPA工具 - >从实体生成表格”

但是eclipse因为这个奇怪的错误而失败了:

Exception in thread "main" javax.persistence.PersistenceException: Found 'javax.persistence.provider' property in the map but the value is not a String. Found object : 'null'.
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:131)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.buildEntityManagerFactory(Main.java:94)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:80)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:68)

这是我的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="myApp" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/superng"/>
        <property name="javax.persistence.jdbc.user" value="postgres"/>
        <property name="javax.persistence.jdbc.password" value="changeit"/>
        <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
        <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
        <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>
    </properties>
</persistence-unit>

为什么会失败?

1 个答案:

答案 0 :(得分:1)

我认为persistence.xml没有问题,但是java-ee-jar和另一个包含javax.persistence.*包的jar之间存在冲突。你需要修改java-ee jar或确保在类路径中只有一个版本的javax.persistence.*包。