https://github.com/binakot/java-inheritance-into-postgresql-jsonb-mapping
The demo project with mapping of Java objects inheritance into PostgreSQL JSONB columns via Jackson and MyBatis.
https://github.com/binakot/java-inheritance-into-postgresql-jsonb-mapping
hacktoberfest jackson java jsonb mybatis orm postgresql spring
Last synced: 12 months ago
JSON representation
The demo project with mapping of Java objects inheritance into PostgreSQL JSONB columns via Jackson and MyBatis.
- Host: GitHub
- URL: https://github.com/binakot/java-inheritance-into-postgresql-jsonb-mapping
- Owner: binakot
- License: mit
- Created: 2019-02-08T14:36:58.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-23T18:59:15.000Z (over 4 years ago)
- Last Synced: 2025-04-07T11:47:07.332Z (about 1 year ago)
- Topics: hacktoberfest, jackson, java, jsonb, mybatis, orm, postgresql, spring
- Language: Java
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Java inheritance into PostgreSQL JSONB mapping
The demo project with mapping of Java objects inheritance
into PostgreSQL JSONB columns via Jackson and MyBatis.
## Development
To build & test:
```bash
$ ./gradlew build test
```
## Running on localhost
To run application on localhost:
```bash
$ ./gradlew bootRun
```
Required `PostgreSQL` running on port `5432` with database schema.
It can be done with Docker container:
```bash
$ docker run \
--name postgres \
-e POSTGRES_DB="postgres" \
-e POSTGRES_USER="postgres" \
-e POSTGRES_PASSWORD="postgres" \
-v postgres_data:/var/lib/postgresql \
-v ${PWD}/src/main/resources/sql/init.sql:/docker-entrypoint-initdb.d/1.init.sql \
-v ${PWD}/src/main/resources/sql/data.sql:/docker-entrypoint-initdb.d/2.data.sql \
-p 5432:5432 \
-d postgres:latest
```
## Running in Docker (the easiest start)
To package the application into jar file:
```bash
$ ./gradlew bootJar
```
To build the application docker image:
```bash
$ docker-compose build
```
To run in Docker with PostgreSQL database:
```bash
$ docker-compose up -d
```
To stop the application and PostgreSQL database:
```bash
$ docker-compose down --volumes
```
---
## Examples
### Vehicle
SQL:
```sql
id | 1
type | VEHICLE
latitude | 45.047579
longitude | 38.963983
course | 10
speed | 15
attributes | {"model": "Toyota Camry", "regNumber": "A 123 BC 777"}
```
JSON:
```json
{
"id": 1,
"type": "VEHICLE",
"latitude": 45.047579,
"longitude": 38.963983,
"course": 10,
"speed": 15,
"model": "Toyota Camry",
"regNumber": "A 123 BC 777"
}
```
### Employee
SQL:
```sql
id | 3
type | EMPLOYEE
latitude | 45.026158
longitude | 38.927763
course | 30
speed | 35
attributes | {"name": "John Doe", "phoneNumber": "8-800 2000 600"}
```
JSON:
```json
{
"id": 3,
"type": "EMPLOYEE",
"latitude": 45.026158,
"longitude": 38.927763,
"course": 30,
"speed": 35,
"name": "John Doe",
"phoneNumber": "8-800 2000 600"
}
```
---
## P.S.
Thanks to @0ffer, it was his idea and initial implementation.