我不明白为什么我的jpql表达式是错误的。我想得到没有从我的数据库中删除的自行车列表,目前正在租赁。你能帮助我吗?
@Data
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Basic(optional = false)
@Column(nullable = false)
private boolean isRemoved;
}
@Data
@Entity
@NamedQueries({
@NamedQuery(name = "Bike.findRent", query = "SELECT b FROM Bike b WHERE NOT b.isRemoved AND b.isRent")
})
public class Bike extends AbstractEntity {
@Basic(optional = false)
@Column(nullable = false)
private boolean isRent;
}
@Repository
public class BikeDao extends BaseDao<Bike> {
public BikeDao() {
super(Bike.class);
}
public List<Bike> findRent() {
return em.createNamedQuery("Bike.findRent", Bike.class).getResultList();
}
}
在我运行我的spring应用程序并通过postman尝试发布自行车数据之后。但是,
Caused by: org.eclipse.persistence.exceptions.EntityManagerSetupException:
Exception Description: Deployment of PersistenceUnit [default] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.7.7.v20200504-69f2c2b80d): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [SELECT b FROM Bike b WHERE NOT b.isRemoved AND b.isRent].
[47, 55] The right expression is not a valid expression.
这是什么意思?我查不出哪里出了问题。
1条答案
按热度按时间t3psigkw1#
根据jpa规范(4.5 where条款):
where子句定义如下:
where_clause ::= WHERE conditional_expression
在条件表达式中,只能使用可用简单表达式的组合,例如comparison、between、in、like、null comparison(aka is null)、empty collection、collection member和exist表达式。因此,您应该按照以下方式更正您的查询: