I'm using jsonb in springboot(2.1)+postgres(10.5)+hibernate(5.3.7).
Following are changes in file:
....
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.3.5</version>
</dependency>
....
```
@Entity(name = "Event")
@Table(name = "event")
@TypeDefs({
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
@TypeDef(name = "int-array", typeClass = IntArrayType.class),
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class),
@TypeDef(name = "jsonb-node", typeClass = JsonNodeBinaryType.class),
@TypeDef(name = "json-node", typeClass = JsonNodeStringType.class),
})
public class Event {
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private List<Location> alternativeLocations = new ArrayList<Location>();
//Getters and setters omitted for brevity
}
```
On running springboot application it given below error:
nested exception is org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [jsonb]
All other settings are standard sprintboot settings working with postgres. Post creation of this above error was coming.
Please let me know possible reason for same, Thanks in advance :)
JSONB stands for “JSON Binary” or “JSON better” depending on whom you ask. It is a decomposed binary format to store JSON. JSONB supports indexing the JSON data, and is very efficient at parsing and querying the JSON data. In most cases, when you work with JSON in PostgreSQL, you should be using JSONB.
Hibernate's PostgreSQL dialect does not support the JSONB datatype, and you need to register it.
I am using a more current release 2.4.3 of the hibernate-types-52 classes and was getting the same error.
I resolved it by using only the single typedef I needed on my entity class.
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
Postgres 9.4, Java 11, Hibernate 5.3.7
@Entity(name = "audit")
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
public class Audit {
@Type(type = "jsonb")
@Column(name="audit_data", columnDefinition = "jsonb")
private Map<String,Object> auditData;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With