简体   繁体   English

Hibernate EntityManager合并不更新空白更改

[英]Hibernate EntityManager merge not updating whitespace changes

I am trying to update an existing database entry using Hibernate and PostgreSQL (9.5) so that white space is trimmed from strings. 我正在尝试使用Hibernate和PostgreSQL(9.5)更新现有的数据库条目,以便从字符串中修剪空白。 For example ... 例如 ...

...
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();

Else where in my code I successfully update other fields, for example the updatedAt time field in the example above. 在我的代码中的其他地方,我成功更新了其他字段,例如上例中的updatedAt time字段。 However, I cannot remove trailing white space from the locale field. 但是,我无法从语言环境字段中删除结尾的空格。 I could, if I wanted to change the locale field to something else entirely, for example using something like this ... 我可以,如果我想将语言环境字段完全更改为其他内容,例如使用类似这样的内容...

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

This will change the locale value. 这将更改区域设置值。 I just cannot remove white space. 我就是无法删除空白。 Any ideas? 有任何想法吗?

we need more info (ex Entity and Schema Data Definition). 我们需要更多信息(例如实体和模式数据定义)。 check if it uses a char instead of varchar in Schema. 检查是否在架构中使用char而不是varchar。 if it uses char it would have same length appended with empty space. 如果使用char,它将具有相同的长度,并附加空白。

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

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