hibernate-json-org-contributor

A type contributor allowing Hibernate to use the commonly known org.json.JSONArray and org.json.JSONObject. Used for PostgreSQL types json/jsonb and MySQL type json.

License

License

Categories

Categories

JSON Data Hibernate ORM
GroupId

GroupId

com.mopano
ArtifactId

ArtifactId

hibernate-json-org-contributor
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

hibernate-json-org-contributor
A type contributor allowing Hibernate to use the commonly known org.json.JSONArray and org.json.JSONObject. Used for PostgreSQL types json/jsonb and MySQL type json.
Project URL

Project URL

https://github.com/mopano/hibernate-json-org-type
Source Code Management

Source Code Management

https://github.com/mopano/hibernate-json-org-type

Download hibernate-json-org-contributor

Dependencies

compile (2)

Group / Artifact Type Version
org.hibernate : hibernate-core jar 5.2.0.Final
org.json : json jar 20171018

Project Modules

There are no modules declared in this project.

org.json datatype contributor for Hibernate ORM 5.2+

If you need to use org.json.JSONArray and org.json.JSONObject objects in your JPA entities and already use Hibernate as your JPA provider, this is the plugin for you, so long as Hibernate, you are using the 'org.json:json' dependency version 20171018 or newer.

Set-up for testing environment:

  • PostgreSQL 9.2 server or newer, running on port 5432
  • MySQL 8.0.3 server or newer, running on port 3306
  • Username, password and database hibernate_orm_test with full privileges that database on both servers.

Compiling:

Assuming you have your JAVA_HOME environment variable pointing to JDK8

./gradlew clean build

If you want to build without running the tests, use assemble instead of build.

To make the final jar available for your Maven or compatible project type that uses the Maven repository, run:

./gradlew publishToMavenLocal

Now you just need to add the dependency to your project's pom.xml.

<dependency>
    <groupId>com.mopano</groupId>
    <artifactId>hibernate-json-org-contributor</artifactId>
    <version>1.0</version>
</dependency>

Or if you're using Gradle:

dependencies {
    compile group: 'com.mopano', name: 'hibernate-json-org-contributor', version: '1.0'
}

Configuring against the default:

To use a custom configuration, you must implement the com.mopano.hibernate.org.json.spi.JsonSettings class and override any settings for which you do not wish to use the default.

You must list the class you've created as a standard Java service, by creating the file META-INF/services/com.mopano.hibernate.org.json.spi.JsonSettings in your resources directory, and adding the fully qualified class name of your implementation in it.

Be sure to read the JavaDoc hints.

Potential pitfall:

If your application is loaded after Hibernate, instead of alongside it, it might not load the type contributor. This can happen if you use Hibernate on a Glassfish server. In this case you would need to add it to Glassfish's classpath the same way you added Hibernate, as it is not the default provider.

Database dialect detection may fail with custom dialects, in which case you need to use a JsonSettings confirguration.

com.mopano

Mopano

Mopano

Versions

Version
1.0