Stephan
Stephan

Reputation: 43053

JPA - Persisting LOB properties on Postgresql

I have a field defined like this

private java.sql.NClob details;

When I try to build to create an entity manager, I get the following exception :

Caused by: org.hibernate.MappingException: Could not determine type for: java.sql.NClob, at table: messages, for columns: [org.hibernate.mapping.Column(details)]

The table doesn't exist yet in the database.

What should I tell Hibernate ?

Upvotes: 5

Views: 4132

Answers (3)

Stephan
Stephan

Reputation: 43053

Here how I solve my problem :

@Column(length=100000)
private String details;

Upvotes: 4

araqnid
araqnid

Reputation: 133682

Since you're using postgresql, maybe it's easiest to map the column as a normal clob, rather than a nclob, since postgresql doesn't have separate nvarchar etc. types.

Upvotes: 1

Stanislav Levental
Stanislav Levental

Reputation: 2235

@Lob indicates that the property should be persisted in a Blob or a Clob depending on the property type: java.sql.Clob, Character[], char[] and java.lang.String will be persisted in a Clob. java.sql.Blob, Byte[], byte[] and Serializable type will be persisted in a Blob.

@Lob
public String getFullText() {
    return fullText;
}

@Lob 
public byte[] getFullCode() {
    return fullCode;
}

If the property type implements java.io.Serializable and is not a basic type, and if the property is not annotated with @Lob, then the Hibernate serializable type is used.

Upvotes: 1

Related Questions