0

Tables

 @Data
 @Entity
 @Table(name = "A")
 class A {
    private Long id;
    private Long bId;
 }

 @Data
 @Entity
 @Table(name = "B")
 class B {
    private Long id;
    @Enumerated(EnumType.STRING)
    private Status status;
 }

enum Status {
NEW,
VALIDATED,
ARCHIVE
}

I have a following native query

@Query(value = "SELECT cast(a.id as varchar) FROM a
INNER JOIN b on a.id = b.id
WHERE a.id = :id AND
b.status = 'NEW'", // here I need smth like b.status = '" + Status.NEW + "' ",
nativeQuery = true)
Set<UUID> findIdByStatuses(@Param UUID id)

Instead of b.status = 'NEW', I need smth like b.status = '" + Status.NEW + "' ",

to get a compile error when name of Status changes. But it is not working like this. And the question is how to reach that desirable concatenation inside of native query without method argumetns

3
  • how about having enum method toString()? Status.NEW.toString() Commented Dec 20, 2020 at 11:21
  • Did not work either. Now I started thinking that I can integrate my variables only through @Param in method arguments Commented Dec 20, 2020 at 11:34
  • Please see if stackoverflow.com/questions/58453768/… can solve your problem. Commented Dec 20, 2020 at 13:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.