P
P
piatachki2018-03-05 14:55:57
Java
piatachki, 2018-03-05 14:55:57

Why is a String field with @Lob annotation stored as a number?

Hello )
The problem is that when saving an entity with a field

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

the entity is stored in the database as a number (it is not clear where it comes from), and it increases by one with each new saved entity, as if it were an ID. There is only one context, saving by the regular method through the CrudRepository. Column type in the database - TEXT.
The only thing is that the setter is built like a builder
public MyEntity setContent(String content) {
   this.content = content;
   return this;
}

Could this be the reason for this behaviour?
If you remove the @Lob annotation, then everything works fine. I'm kind of stuck.
Stack: Spring Boot 2, Hibernate 5.0.1, Postgres

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-03-05
@piatachki

There are two types of LOBs in PostgreSQL - BLOB and CLOB . Judging by the fact that the entity field is of type String, you need the second one. And this needs to be added:

@Lob @Type(type = "org.hibernate.type.TextType")
private String content;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question