I have spring boot project, which uses hibernate spatial. I also have a json file, that contains data, which I would like to import to a database (postgresql).
I would prefer if I could execute this as a separate java "script" application from the commandline or from IntelliJ IDEA. But, it would still use the hibernate classes of the main application (entities for example). What I would want to do is:
- Launch the java program from commandline with a parameter that tells the location of the json file, which contains the data
- Parse the json file somehow, and loop through its main array.
- On each loop, I would want to get some values from the current json array object, and then instantiate a hibernate entity object, and save it to the database.
What do you think would be the best way to achieve this?
I found spring-boot-starter-batch module, but it feels like it has so much overhead and complexity for a such an easy and simple task to do. What I'm also wondering why is there zero examples of loading data from a json file? One could think that is very common task.
I also found ApplicationRunner (one example also here), which could fit for the job. It is run on application startup. I wouldn't want to run it always on startup, but at least I could run it now, and then disable that code. But I don't know how to use it fully really. Any help is much appreciated!