JPA @Lob property encoding not working with PostgreSQL text
Asked Answered
V

1

6

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.

Viceregal answered 21/3, 2016 at 2:26 Comment(1)
FYI: the correct PostgreSQL's JDBC parameter is charSet=UTF-8 (for 8.4 too)Hines
L
2

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

Lycanthrope answered 21/3, 2016 at 8:48 Comment(3)
That's it @D0dger! Solved my problem! Thank you very much!Viceregal
In the latest it's not working. Class not found org.hibernate.type.StringClobTypeArgillaceous
Have you tried org.hibernate.type.MaterializedClobType?Lycanthrope

© 2022 - 2024 — McMap. All rights reserved.