How to convert a SQL query into hibernate criteria?

What is the best way to convert JSON to an SQL Query?

  • I will give a json object it should convert it to a sql query based on the data.

  • Answer:

    First you'll have to explain what the query is supposed to achieve.

Toby Thain at Quora Visit the source

Was this solution helpful to you?

Other answers

JSON is a definition of data.Data which can be used to translate as filter mechanisms.ex.[{name:'bob', age:21}, {name:'alice'}]could then roughly be translated toSELECT *FROM [People]WHERE  (Name = 'bob' AND age=21) OR  (Name = 'alice')It gets a bit more complicated when you use pseudo expressions like {age:'>=21'} or {name:'*lice'} Because you need to come up with your own algorithm that handles that parsingLastly, from C#, using LINQ its just a matter of filteringIEnumerable<Person> persons = dbContext.Persons();persons = persons.Where(person => http://person.Name..

JC Guerrero

JSON suport is coming in SQL Server 2016, http://sqlwithmanoj.com/2015/05/09/microsoft-announced-sql-server-2016-new-features-and-enhancements/ Though it will not be a new datatype like XML, but will use VARCHAR or NVARCHAR instead. SQL engine will have similar syntax like XML to parse the new JSON object. Export SQL table to JSON format: http://sqlwithmanoj.com/2015/06/01/working-with-json-data-and-sql-queries-sql-server-2016/ Importing JSON string to SQL table is coming in CTP-3 My blog: https://sqlwithmanoj.quora.com

Manoj Pandey

Well, if you are using Java. Hibernate, Jackson would make some sense here.I can think of an way,First convert the JSON using Jackson library. This now becomes a simple POJO. Now this POJO can be mapped in Database using Hibernate Configuration and Hibernate Mapping and then yu can simply use, query.criteria() and query.list() on the dataset which will work as expected.I have not tried this out but this should be a way out to convert JSON to SQL without coding. Everything can be driven through XML configurations and Standard Libraries.Hope, you will try this once.

Palash Kanti Kundu

I really don't know what you're talking about, but hey, I wrote this thing: https://github.com/goodybag/mongo-sql that actually exactly matches your description.

John Fawcett

I would suggest to use http://www.newtonsoft.com/jsonJson library , and then make a class that based on the object, then make a list of that object and de-serialize it to the list and use LINQ to do your queries.exmaplehttp://www.newtonsoft.com/json/help/html/DeserializeObject.htm

Venu S Dharan

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.