I have following problem with multilanguage database. I needed to store properties file per language to database. I used CLOB datatype for it and String field in an entity, which I was converting java.util.Properties to String on @PrePersist and @PreUpdate and in @PostLoad I turned it back from string to properties. This was working fine for german localization, however was not working for french. It is probably worth mentioning that I am using ISO8859-1 encoding everywhere
@Lob
// length is there only for hypersonic sql (junit tests), otherwise clob(255) is generated
@Column(name = "PROPERTIES_BLOB", length = 65536, nullable = false)
private String blob;
@Transient
private Properties properties;
@PostLoad
public void postLoad() throws IOException
{
try (StringReader reader = new StringReader(blob))
{
this.properties = new Properties();
this.properties.load(reader);
}
}
I have tried escaping special french characters and then the clob was fine from my point of view. But, when I was loading the data to the entity, JPA did unescape the characters and screwed up the french characters.
I have solved the problem by turning my clob to blob and column in an entity to byte[] array, and this allowed me to work around this problem and unescaping using the Properties.load(InputStream stream) method, which works ok even for French characters
My question is however how to manage it by keeping the clob in DB (it is clearly visible what it contains and so on). I would need to force JPA or hibernate not to unescape characters when writingdata from clob to string. Is there some configuration property for it?