0

I am new to jpa and trying to write a query. Query is related to enum. I have an enum, I want to fetch records based on enum.

In below query deviceStatus is an enum. when I defined lk.deviceStatus =LOCKER_CLOSE giving error:

Unknown column 'LOCKER_CLOSE' in 'where clause'

@Query("SELECT lk from Locker lk where lk.terminal.id=:terminalId 
and lk.deviceStatus =LOCKER_CLOSE and lk.isEmpty =true  
and :size IS NULL OR lk.lockerSize=:size")


public List<Locker> testOneFunction(@Param("terminalId") String 
 terminalId, @Param("size") LockerSize size);
Nicholas K
  • 15,148
  • 7
  • 31
  • 57
Rishabh
  • 89
  • 1
  • 4
  • 11
  • 2
    Can you try to add quotes around `LOCKER_CLOSE` ? I guess that without them, it is considered as a column name which obviously does not exist. – Arnaud Denoyelle Jan 24 '19 at 09:20
  • try prepending `LOCKER_CLOSE` with the fully qualified domain name of the enum. E.g. `com.example.MyEnum.SOME_CONSTANT` – Lino Jan 24 '19 at 09:25
  • Possible duplicate of [Problems with making a query when using Enum in entity](https://stackoverflow.com/questions/8217144/problems-with-making-a-query-when-using-enum-in-entity) – Daria Pydorenko Feb 01 '19 at 17:36

1 Answers1

1

Try using fully qualified enum class e.g.

SELECT lk from Locker lk where lk.terminal.id=:terminalId 
and lk.deviceStatus = com.somepackage.MyStatusEnum.LOCKER_CLOSE 
and lk.isEmpty =true and :size IS NULL OR lk.lockerSize=:size