我正在尝试使用以下代码在 ObjectDB 数据库中保存一些 UTF-8 字符串:
ResourceBundle entries = Utf8ClassLoader.getBundle("localization/language", "fa-IR"); // fa-IR is a UTF-8 and RTL language
Enumeration<String> keys = entries.getKeys();
for (String key = keys.nextElement(); keys.hasMoreElements(); key = keys.nextElement()) {
ResourceEntity entity = new ResourceEntity();
entity.setId(new ResourceEntity.PKC(key, locale));
entity.setValue(entries.getObject(key));
resourceDAO.persistOrUpdate(entity);
}
该模型:
@Entity
public class ResourceEntity {
@EmbeddedId
private PKC id;
private Object value;
// Getters and setters omitted
@Embeddable
public static class PKC {
String key;
String locale;
public PKC() {}
public PKC(String key, String locale) {
this.key = key;
this.locale = locale;
}
// Getters and setters omitted
}
}
本地化/语言_fa_IR.properties 存在并正确打开。
DAO 的 persistOrUpdate 方法只不过是事务中的 EntityManager.persist 函数。(如果密钥存在,EntityManager.merge 是否存在)
但是当我打开 ObjectDBViewer 时,我看到了这个:
如何在不更改字符的情况下保存字符串?