Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA @Lob property encoding not working with PostgreSQL text

JPA Mapping

I'm Using JPA with Hibernate. I have an entity with a @Lob property

@Column(nullable=false)
@Lob
private String text;

I'm using PostgreSQL 8.4 and the Entity was correctly mapped with the column

"text" text NOT NULL

My view pages are using UTF-8 encoding and my URL Connection is also using the proper encoding:

<property name="url" value="jdbc:postgresql://myhostip:port/mydb?useUnicode=yes&amp;characterEncoding=UTF-8" />

Also, my client_encoding on posgreSQL is Unicode (using Query Tool) or UTF-8 (using psql).

The problem

Although I can read/persist the data, when I display it there are some encoding problems like showing ��.

Another information is, on the same entity I have another String properties there are displayed correctly for the same content of the @Lob property.

I have also exported the text property from psql to a test.txt file and the content is ok.

I've tested the value of the property just before persisting (debugging) and the value is correct.

like image 319
Rafael Takashima Avatar asked Mar 21 '16 02:03

Rafael Takashima


1 Answers

Based on this try to add annotation @Type(type="org.hibernate.type.StringClobType") after @Lob

like image 85
Javasick Avatar answered Nov 07 '22 01:11

Javasick