Hibernate mapping exception for List field when using @Formula

I have an oracle table MYTABLE which has 3 columns as mentioned below.

|id | myclob_column | column3|

It has one column (myclob_column) which is clob data (json). Sample clob data is below.

{
"id" : 10001
"name" : "Rahul",
"keyvalue" : [ {"key" : "100", "value" : "A"}, {"key" : "200", "value" : "B"} .....]
}

KeyValue is defined as a class in my project like below.

@Data
public class KeyValue {

 private String key;
 private String value;

}

I am using org.hibernate.annotations.Formula annotations on name & keyvalue field.

@Data
@Entity
@Table(name = "MYTABLE")
public class MyEntity {

@Id
private String id;

@Formula("JSON_VALUE(myclob_column, '$.name')")
private String name;

@Formula("JSON_VALUE(myclob_column, '$.keyvalue[*]')")
private List<KeyValue> keyvalue;

}

While running the Spring Boot application, I am getting error for keyvalue field and application is not getting started for this.

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: MYTABLE, for columns: [org.hibernate.mapping.Formula(JSON_VALUE(myclob_column, '$.keyvalue[*]'))]

Can you please suggest what is the issue.

Database - Oracle, Hibernate Version - 5.6

Think about it. How should Hibernate know how to deserialize whatever it gets from the database into a List<KeyValue>? It simply can’t do it, because it has no idea what the format is. You can implement a custom AttributeConverter<List<KeyValue>, String> and apply it to this attribute with @Convert(converter = MyAttributeConverter.class)

1 Like

ok, thanks for the suggestion. Got it.