0

my entity code

Is there a way i can search in the json map by a JPQL query ?

I tried with Blaze-Persistence API but when i write :

@EntityGraph(value = "record")
@Query(value = "SELECT r from Records r WHERE JSON_GET(r.data , '123') = :value")
List<Record> findAllByViewAndColumn(String value);

JSON_GET is not recognizable. I referenced to JPQL how to search on JSON Map by KEY name or VALUE , but its not working for me ...

  • Hey there! Which Hibernate, DB and Blaze-Persistence versions are you using? Also, are you sure that the Blaze-Persistence integration is setup correctly? – Christian Beikov Nov 29 '22 at 10:53
  • implementation group: 'com.blazebit', name: 'blaze-persistence-core-api', version: '1.6.8' -- thats the blaze-persistence version From logs i can see i'm using Hibernate ORM core version 5.6.11.Final and (MySQL 8.0) // I have added the dependancy also in other classes when i try to build CriteriaBuilder thru blaze APi it works but in my repository it doesn't work . – Martin Bozhinov Nov 29 '22 at 11:28
  • So the same query restriction works with Blaze-Persistence `CriteriaBuilder`? That's odd because the functions are registered into the Hibernate `EntityManagerFactory`. Can you share an example for this? – Christian Beikov Nov 29 '22 at 14:07
  • I think you didn't understand me , my bad . I putted pictures of what i meant . – Martin Bozhinov Nov 29 '22 at 16:03
  • You mean the JSON_GET function or ? I cant understand the flow i thought that im only putting the dependencies of the library and then this function works in my JPQL i mean the (JSON_GET) function , but now i'm supposing that i need to implement this class you have sended . I implemented it and configuration.registerFunction() is this what i should use and i cant find any other sources how to implement it to search in the json? – – Martin Bozhinov Nov 29 '22 at 18:32
  • The functions that Blaze-Persistence comes with are registered and then you can just use them in JPQL, but you need to configure it properly. You don't have to register custom functions for this particular purpose. The `config.createCriteriaBuilderFactory(entityManagerFactory);` part will register functions into the `EntityManagerFactory`. – Christian Beikov Nov 30 '22 at 04:27
  • Allright i tried with lower cases , with other dummy values and it dont work if i write it the way you have like that `The usage would look like the following: FROM Permission p WHERE JSON_GET(p.assignee, 'jsonKey') = 'someValue'` – Martin Bozhinov Nov 30 '22 at 06:34
  • Tryout one of the quickstarts (https://github.com/Blazebit/blaze-persistence/#quickstart). I guess you just forgot to configure something. – Christian Beikov Nov 30 '22 at 11:55
  • Just tried with the Spring-Boot archetype , i have added Json data to the Cat entity , and in the repository is the same thing, it doesn't recognize the json_get function .... – Martin Bozhinov Nov 30 '22 at 13:12
  • Note that when you test this in this quickstart example, you will have to configure a database different from H2, because H2 doesn't support that function. – Christian Beikov Dec 01 '22 at 10:19

0 Answers0