JPQL不断抛出表达式不是有效的条件表达式

时间:2017-10-12 06:49:28

标签: jpa eclipselink jpql tomee

我已经走到了尽头。我一直在说:

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;

}

我的道:

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羽流7.0.3

提前致谢!

1 个答案:

答案 0 :(得分:2)

找到解决方案:

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