0

Using below SQL in mysql directly, I can get the items I want successfully, saying "['item1', 'item2']".

select JSON_EXTRACT(specific_job, '$.items') from t_job where id = 1;

But when I tried to use that in my Spring project with JPA, like below.

@Query(value = "select JSON_EXTRACT(specific_job, '$.items') from t_job where id = ?1", nativeQuery = true)
String findJobItems(Long jobId);

It's very strange that, when calling this function, the query seems work, but only returns the first letter of the items, like "[".

Is this a bug of spring data JPA? Or is there any better way to extract json fields in Spring data JPA?

1 Answer 1

2

You have to cast the items as varchar.

CAST(myColumn as CHAR(50))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this works for me. And I have found that I could cast items to varchar without the char length. CAST(myColumn as CHAR)

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.