I’m working on a Spring Boot application that uses Hibernate ORM and MySQL. I’m having encoding problems with Hungarian characters.
When I run queries using JdbcTemplate, everything works fine and I get proper “ő” characters. However, when I use Hibernate entities, these characters show up as question marks (�).
My database uses utf8_hungarian_ci collation and utf8 charset.
Configuration in application.properties:
spring.jpa.database=MYSQL
spring.jpa.hibernate.ddl-auto=validate
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/myapp?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=admin
spring.datasource.password=secret
I have Employee and Permission entities with a many-to-many relationship:
Employee.java:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "employee_permission",
joinColumns = @JoinColumn(name = "emp_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "perm_id", referencedColumnName = "id"))
private Set<Permission> permissions;
public Set<Permission> getPermissions() {
return permissions;
}
Permission.java:
@ManyToMany(mappedBy = "permissions")
private Set<Employee> employees;
When I call:
loggedInEmployee.getPermissions();
All “ő” characters become �.
UPDATE: I tried adding a new employee with name “tűzoltó főparancsnok” and got this error during login:
"error":"Internal Server Error","exception":"java.io.CharConversionException"
,"message":"Not an ISO 8859-1 character: ű"
What configuration am I missing?