0
我想用Hibernate和PostgreSQL(9.5)更新現有的數據庫條目,以便從字符串中刪除空白區域。例如...Hibernate EntityManager合併不更新空白更改
...
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時間字段。但是,我無法從locale字段中刪除尾隨空白。我可以,如果我想的區域設置字段更改爲別的東西完全,例如使用這樣的事情...
geoLocationLocale.setLocale(new BigInteger(16, new Random()).toString(10));
這將改變區域價值。我無法刪除空白區域。有任何想法嗎?
噢,真好!而已。 locale字段是字符(8),而不是varchar。謝謝!將接受 – SiLaf