user15599360
user15599360

Reputation:

IllegalArgumentException when trying to create @Query in Spring data jpa

I try to get a field with my query ( status - just a simple enum ).

@Query("SELECT Order.status from Order o WHERE o.id = :id")
Status getStatusById (@Param(value = "id")  long id);

This is the exception I get right on the start before this query is invoked.

Caused by: java.lang.IllegalArgumentException: Validation failed for query for method
Caused by: java.lang.NullPointerException: Cannot read field "value" because "s1" is null

Important Part of my order entity

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Table(name = "orders")
@ToString
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Enumerated(EnumType.STRING)
    private Status status;
}

Upvotes: 0

Views: 4481

Answers (1)

user15599360
user15599360

Reputation:

This solved my problem

@Query("SELECT o.status FROM Order o WHERE o.id=:id")

Upvotes: 4

Related Questions