【发布时间】:2020-05-28 12:12:28
【问题描述】:
我在使用 JPA EntityManager 时遇到了问题,尝试如下简单查询:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javax.persistence.*;
import tables.TeamMember;
public class BoburvikDatabase extends Application {
public EntityManagerFactory emf;
public EntityManager em;
public BoburvikDatabase BD;
public Stage primaryStage;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
emf = Persistence.createEntityManagerFactory("BoburvikDatabasePU");
em = emf.createEntityManager();
this.BD = this;
TypedQuery<TeamMember> q1 = em.createQuery(
"SELECT * FROM \"TeamMember\" WHERE \"MEMBER_ID\"=1000;",
TeamMember.class
);
TeamMember result = q1.getSingleResult();
System.out.println(result);
em.close();
}
public static void main(String[] args) {
launch(args);
}
}
但我收到错误消息:
[27, 27] A select statement must have a FROM clause.
[7, 7] The left expression is missing from the arithmetic expression.
[9, 27] The right expression is not an arithmetic expression.
[47, 52] '1000;' is not a valid numeric value.
实体类包含在持久性单元中,我尝试在 pgAdmin 中运行 SQL 命令并且它有效,我认为从输出中的这一行判断我正在连接到数据库:
[EL Info]: connection: 2020-05-28 13:58:17.977--ServerSession(927866519)--
file:/D:/Java/boburvik/BoburvikDatabase/dist/run285579090/BoburvikDatabase.jar_BoburvikDatabasePU
login successful
有什么想法可能是错误所在吗?
【问题讨论】: