-1

ALL>

I have here a named query to update and replace records.

@NamedQuery(name = POST.UPDATE_POST_MESSAGE, query = "UPDATE Post p SET p.message = REPLACE(p.message, :value, 'ANONYMOUS')"

I wanted the "old string" to be parameterized but it shows an error of

Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of value that does not exist in the query string UPDATE Post p SET p.message = REPLACE(p.message, :value, 'ANONYMOUS').

here's the code in my dao layer:

private static final String VALUE = "value";

public void updateMessage(String value) {
  EntityManager entityManager = createEntityManager();

  entityManager.createNamedQuery(POST.UPDATE_POST_MESSAGE)
     .setParameter(VALUE, value)
     .executeUpdate();
}

I am not sure if we can use a parameter inside the replace function, been searching everywhere and i cant find an answer. If not possible, can someone help/recommend a way to replace records using a parameter.

overflown
  • 11
  • 4

1 Answers1

0

Here you assigned parameter value to VALUE variable but using value((lower case ).

imomins
  • 24
  • 1
  • 4