【问题标题】:JPQL keep throwing The expression is not a valid conditional expressionJPQL 不断抛出 The expression is not a valid conditional expression
【发布时间】:2018-03-24 00:13:52
【问题描述】:

我已经走到了尽头。我不断得到:

Exception Description: Syntax error parsing [SELECT a FROM UserEntity u JOIN u.addresses a WHERE u.email =: email]. 
[52, 69] The expression is not a valid conditional expression.
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1585)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

我的实体:

@Getter
@Setter
@EqualsAndHashCode
@Entity
@Table(name = "ADDRESS", schema = "Test")
public class AddressEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private int id;

    @Basic
    @Column(name = "address_name")
    private String addressName;

    @Basic
    @Column(name = "address_content")
    private String addressContent;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private UserEntity user;

@Getter
@Setter
@EqualsAndHashCode
@Entity
@Table(name = "USER", schema = "Test")
public class UserEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private int id;

    @Basic
    @Column(name = "email")
    private String email;

    @Basic
    @Column(name = "password")
    private String password;

    @OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
    private List<AddressEntity> addresses;

}

我的 DAO:

Query query = em.createQuery("SELECT a FROM UserEntity u JOIN u.addresses a WHERE u.email =: email");
        query.setParameter("email", email);
        return query.getResultList();

我不知道出了什么问题。我已经用 allArgsConstructor 尝试过,还尝试从 AddressEntity 中获取它。

我正在使用 TomEE Plume 7.0.3

提前致谢!

【问题讨论】:

    标签: jpa eclipselink jpql apache-tomee


    【解决方案1】:

    找到解决办法:

    SELECT a FROM UserEntity u JOIN u.addresses a WHERE u.email =: email
    

    应该是:

    SELECT a FROM UserEntity u JOIN u.addresses a WHERE u.email = :email
    

    【讨论】:

    • 只是为了突出显示已修复的内容:冒号和您的命名参数之间不应有空格
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2016-06-19
    相关资源
    最近更新 更多