Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Enum as NamedQuery parameters in JPA

I have an Entity with a enum attribute and a couple on NamedQueries. One of these NamedQueries has the enum attribute as a parameter i.e.

SELECT m FROM Message m WHERE m.status = :status

When i try to ru n the query i get the following error;

Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class my.package.Status for parameter status with expected type of class my.package.Status from query string SELECT m FROM Message m WHERE m.status = :status.

I'm using Toplink

How is this? How would i make JPA happy?

like image 736
n002213f Avatar asked Nov 05 '22 13:11

n002213f


1 Answers

Enum objects can be used as query parameters just like any other objects. You query however should probably be:

SELECT m FROM Message m WHERE m.status = :status

Also - have added the @Enumerated in the entity definition?

like image 113
Bozhidar Batsov Avatar answered Nov 12 '22 14:11

Bozhidar Batsov