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.

Community
  • 1
  • 1
  • FYI: the correct PostgreSQL's JDBC parameter is `charSet=UTF-8` ([for 8.4 too](https://jdbc.postgresql.org/documentation/84/connect.html#connection-parameters)) – pozs Mar 21 '16 at 10:50

1 Answers1

2

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

Javasick
  • 2,753
  • 1
  • 23
  • 35