anand mishra
anand mishra

Reputation: 900

How to Dynamically create table from JSON data using Hibernate

I am creating a application in which I am receiving the data in JSON format from Jersey RESTServices.I need to dynamically generate the table using the JSON data and also want to store the values in this table. Let us suppose that I get the data as:

     { "fieldLists":
                     {"fields":[

                                {"name":"field_a","type":"any Java Type"},

                                {"name":"field_b","type":"any Java Type"}
                               ]
                     }
      }

Now I need to create table using this data.I am stuck how to create class and its mapping at run time?

Please suggest which approach will be better?

Upvotes: 0

Views: 1982

Answers (2)

Naros
Naros

Reputation: 21113

An ORM framework is really not an ideal choice for your requirement primarily because they were never designed to support dynamic domain models. While you may use the native sql features of your ORM framework of choice, it's effectively just a wrapper around JDBC.

Using JDBC, you would simply construct the CREATE TABLE DDL statements based on the JSON provided data when a table should be created and then construct the appropriate statements when you need to add, alter, or remove rows.

Upvotes: 1

HuTa
HuTa

Reputation: 178

First you need to create class. Save it to some location. Compile it and load to memory. Add class to hibernate config.

programmatically-compile-and-instantiate-a-java-class

create database in Hibernate at runtime

Upvotes: 0

Related Questions