gpt4 book ai didi

java - EJB QL 语法错误

转载 作者:行者123 更新时间:2023-11-30 04:47:25 27 4
gpt4 key购买 nike

在我的应用程序中,我有以下 2 个实体:

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Commentable implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected Long id;
protected long createdDate;
...
}

@Entity
public class Announcement extends Commentable implements Serializable {

private int type;
private String title;
@Column(columnDefinition = "MEDIUMTEXT")
private String content;
...
}

当我尝试从公告表中获取某些行时,我不断在以下行中收到语法错误:

Query q = em.createQuery("SELECT A FROM Announcement A JOIN Commentable C ON A.id = C.id WHERE A.type=:type ORDER BY C.createdDate DESC");

这是堆栈跟踪:

Caused by: Exception [EclipseLink-8023] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [SELECT A FROM Announcement A JOIN Commentable C ON A.id = C.id WHERE A.type=:type ORDER BY C.createdDate DESC].
Internal Exception: org.eclipse.persistence.internal.libraries.antlr.runtime.EarlyExitException

如果您能告诉我我在这里做错了什么,我将非常感激。

最诚挚的问候,詹姆斯·特兰

最佳答案

如果“公告”扩展了“可评论”,则不需要加入:

select a from Announcement a where a.type = :type order by a.createdDate desc

关于java - EJB QL 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10652405/

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