PGJson

postgres json type support for hibernate

License

License

Categories

Categories

JSON Data
GroupId

GroupId

com.bazarnazar
ArtifactId

ArtifactId

pgjson
Last Version

Last Version

1.3
Release Date

Release Date

Type

Type

jar
Description

Description

PGJson
postgres json type support for hibernate
Project URL

Project URL

https://github.com/bazar-nazar/pgjson
Source Code Management

Source Code Management

https://github.com/bazar-nazar/pgjson

Download pgjson

How to add to project

<!-- https://jarcasting.com/artifacts/com.bazarnazar/pgjson/ -->
<dependency>
    <groupId>com.bazarnazar</groupId>
    <artifactId>pgjson</artifactId>
    <version>1.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.bazarnazar/pgjson/
implementation 'com.bazarnazar:pgjson:1.3'
// https://jarcasting.com/artifacts/com.bazarnazar/pgjson/
implementation ("com.bazarnazar:pgjson:1.3")
'com.bazarnazar:pgjson:jar:1.3'
<dependency org="com.bazarnazar" name="pgjson" rev="1.3">
  <artifact name="pgjson" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.bazarnazar', module='pgjson', version='1.3')
)
libraryDependencies += "com.bazarnazar" % "pgjson" % "1.3"
[com.bazarnazar/pgjson "1.3"]

Dependencies

provided (3)

Group / Artifact Type Version
org.hibernate : hibernate-core jar 4.3.0.Final
org.codehaus.jackson : jackson-jaxrs jar 1.9.13
org.postgresql : postgresql jar 9.2-1002-jdbc4

Project Modules

There are no modules declared in this project.

PGJson

Hibernate extension for PostgreSQL json type support

This projects provide some classes to simplify work with Postgres json data type in hibernate. It includes extended postgres dialect and objects for type def support. This small library allows to store in json field both HashMap(with any nesting level) and custom objects. Also it supports scheme validation and update

Requirements

Library expects that in your project you have following dependencies

  • hibernate core(4.3 or higher)
  • jackson (1.9.13) want to add opportunity to support custom converter
  • PostgreSQL driver(9.2 or higher)

How to use

  • include library into your project
        <dependency>
            <groupId>com.bazarnazar</groupId>
            <artifactId>pgjson</artifactId>
            <version>1.3</version>
        </dependency>
  • set com.bazarnazar.pgjson.JsonPostgreSQLDialect as dialect for hibernate
  • if you want to store custom object
    • create object that extends com.bazarnazar.pgjson.PGJsonObject
    • add this object as type in @Type to your @Entity and your annotate field or getter for this type where object is stored
  • if you want to store collection of objects extend PgJsonCollection and override getReturnedTypeReference() like this
    protected TypeReference getReturnedTypeReference() {
        return new TypeReference<Map<String, SomeType>>() {};
    }
  • if you want to store HashMap
    • simply add com.bazarnazar.pgjson.JsonMapType as type in @Type to your @Entity and your annotate field or getter for this type where Hash map is stored

WARNING!!!

  • If you have native queries in your project, be sure that you adding entity for this query
  • Be careful while editing or passing object for json field. Since it's not immutable changing data directly in this object, can change data in database. It's strongly recommended to create copies

Versions

Version
1.3
1.2
1.1