Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPQL keep throwing The expression is not a valid conditional expression

I've reached dead end with this. I keep getting:

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)

My entities:

@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;

}

My 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();

I have no idea what's wrong. I've already tried it with allArgsConstructor and also tried to fetch it from the AddressEntity.

I'm using TomEE plume 7.0.3

Thanks in advance!

like image 534
Dux_inf Avatar asked Nov 30 '25 16:11

Dux_inf


1 Answers

Found a solution:

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

Should be as:

SELECT a FROM UserEntity u JOIN u.addresses a WHERE u.email = :email
like image 52
Dux_inf Avatar answered Dec 02 '25 05:12

Dux_inf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!