当我尝试将实体映射到 postgresql 中的表时,maven 编译错误

Kha*_*mza 7 java postgresql jpa maven jakarta-ee

我需要你的帮助来使用 PostgresSQL 数据库将实体映射到表,实际上导致此错误的原因是我尝试将实体映射到表,不幸的是 maven 导致了这个我无法识别的问题,所以我必须使用代码优先方法使用 jpa 、 persistance.xml 和 jboss wildfly 将此实体映射到 postgresql 中的表。预先感谢您的支持。

package testdb;

import java.io.Serializable;
import javax.persistence.*;


/**
 * The persistent class for the "HAHA" database table.
 * 
 */
@Entity
@Table(name="Ha_ha", schema="public")
public class Haha implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name="ID_HAHA")
    private long idHaha;

    @Column(name="DESIGNATION")
    private String designation;

    public Haha() {
    }

    public long getIdHaha() {
        return this.idHaha;
    }

    public void setIdHaha(long idHaha) {
        this.idHaha = idHaha;
    }

    public String getDesignation() {
        return this.designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
    }

}
Run Code Online (Sandbox Code Playgroud)

这是错误消息的示例,与 Maven 的输出完全相同:

[ERROR] COMPILATION ERROR : 
    [INFO] -------------------------------------------------------------
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[4,1] package javax.persistence does not exist
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[11,2] cannot find symbol
      symbol: class Entity
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[12,2] cannot find symbol
      symbol: class Table
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[16,10] cannot find symbol
      symbol:   class Id
      location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[17,10] cannot find symbol
      symbol:   class Column
      location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[20,10] cannot find symbol
      symbol:   class Column
      location: class testdb.Haha
    [INFO] 6 errors 
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.759 s
    [INFO] Finished at: 2017-11-19T02:12:34+01:00
    [INFO] Final Memory: 17M/211M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project testdb: Compilation failure: Compilation failure:
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[4,1] package javax.persistence does not exist
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[11,2] cannot find symbol
    [ERROR] symbol: class Entity
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[12,2] cannot find symbol
    [ERROR] symbol: class Table
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[16,10] cannot find symbol
    [ERROR] symbol:   class Id
    [ERROR] location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[17,10] cannot find symbol
    [ERROR] symbol:   class Column
    [ERROR] location: class testdb.Haha
    [ERROR] /C:/Users/anonyme/eclipse-workspace/testdb/src/testdb/Haha.java:[20,10] cannot find symbol
    [ERROR] symbol:   class Column
    [ERROR] location: class testdb.Haha
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Run Code Online (Sandbox Code Playgroud)

Dre*_*lls 8

看来您需要将此依赖项添加到您的 Maven 项目中。

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)