dcalap
dcalap

Reputation: 1072

Persist String variable to Lob with Micronaut Data JDBC

I'm using Micronaut Data JDBC and I have an issue.

I have a @MappedEntity for JDBC with a content field that is a String used in a JPA context as follows:

@Lob
@Column(name = "content")
private String content;

I need to migrate this code to JDBC and I need that this content will be persisted as a Lob as well in a PostgreSQL.

With the current code, I'm just able to store the content as a String.

Any idea of how could I achieve that?

Upvotes: 1

Views: 238

Answers (1)

dcalap
dcalap

Reputation: 1072

For persisting the String content as a LOB, what needs to be done is to annotate the field as follows:

@ColumnTransformer(write = "lo_from_bytea(0, ?::bytea)")
@Column(name = "content")
private String content;

by doing this, PostgreSQL stores an ID in the content column and the data is persisted in the pg_largeobject table as it was desired.

Upvotes: 0

Related Questions