gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:54:10 24 4
gpt4 key购买 nike

我需要你的帮助来使用 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;
}

}

下面是错误消息的示例,与 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

最佳答案

看起来您需要添加 this dependency到您的 Maven 项目。

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>

关于java - 当我尝试将实体映射到 postgresql 中的表时,maven 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47372977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com