繁体   English   中英

Hibernate EntityManager合并不更新空白更改

[英]Hibernate EntityManager merge not updating whitespace changes

我正在尝试使用Hibernate和PostgreSQL(9.5)更新现有的数据库条目,以便从字符串中修剪空白。 例如 ...

...
EntityManager entityManager = EntityManagerHelper.getEntityManager();
entityManager.getTransaction().begin();
...
GeoLocationLocale geoLocationLocale = existingLocales.get(id);
geoLocationLocale.setLocale(geoLocationLocale.getLocale().trim());

long now = Calendar.getInstance().getTimeInMillis();
geoLocationLocale.setUpdatedAt(new Date(now));
entityManager.merge(geoLocationLocale);
...
entityManager.flush();
entityManager.getTransaction().commit();
entityManager.close();

在我的代码中的其他地方,我成功更新了其他字段,例如上例中的updatedAt time字段。 但是,我无法从语言环境字段中删除结尾的空格。 我可以,如果我想将语言环境字段完全更改为其他内容,例如使用类似这样的内容...

geoLocationLocale.setLocale(new BigInteger(16, new Random()).toString(10));

这将更改区域设置值。 我就是无法删除空白。 有任何想法吗?

我们需要更多信息(例如实体和模式数据定义)。 检查是否在架构中使用char而不是varchar。 如果使用char,它将具有相同的长度,并附加空白。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM