-1

I am using Spring boot + Spring Data JPA + PostgreSQL. I have simply class containing some strings.

for example:

public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String name;
    private String surname;
}

I am creating new persons:

Person person = new Person(null, "Roman", "Brzęścikiewicz");

Which contains some polish symbols like "ę" and "ś". When i am saving this to database:

personRepository.save(person);

Then i am left with person saved in database, which received ID and name but not surname example:

id;name;surname
1;Roman;

But when i have surname without polish symbols then i got correct row in database:

id;name;surname
1;Roman;Brzescikiewicz

My application properties:

spring.datasource.url=jdbc:postgresql://localhost:5433/db
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=validate

Adding ?useUnicode=true&characterEncoding=utf8 As suggested on some qestions on stackoverflow won't work.

Any ideas?

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
stream28
  • 141
  • 6

2 Answers2

0

The characteter encoding is wrong. UTF-8 != utf8

characterEncoding=UTF-8

Add it to your jdbc URL

jdbc:postgresql://localhost:5433/db?useUnicode=yes&characterEncoding=UTF-8

You can read an example of same situation here

Community
  • 1
  • 1
cralfaro
  • 5,822
  • 3
  • 20
  • 30
  • Added it to ma jdbc url and tried: characterEncoding=UTF-8 spring.jpa.characterEncoding=UTF-8 spring.jpa.hibernate.characterEncoding=UTF-8 spring.datasource.characterEncoding=UTF-8 hibernate.characterEncoding=UTF-8 and still not working – stream28 Mar 10 '17 at 12:34
  • could you check that your DB schema encoding its also UTF-8? you can connect with some DB client to your DB and check that property – cralfaro Mar 10 '17 at 12:37
  • server encoding is utf8, database encoding is UTF8 with collation en_US.utf8 and same character type, when i am inserting surname with polish symbols via SQL it works, but not with spring data – stream28 Mar 10 '17 at 12:45
  • could you copy here the value of your spring.datasource.url property? – cralfaro Mar 10 '17 at 14:43
0

Solved.

Actually this was veryy stupid problem. I was using PhpPgAdmin to search in database and phppgadmin has bug not displaying polish symbols... in pgadmin4 it is displaying correctly, and if i access data via spring JPA in rest controller it is also working correctly.

stream28
  • 141
  • 6