Avoid CHAR-trimming when using eclipselink

 ̄綄美尐妖づ 提交于 2019-12-24 10:30:03

问题


I have some Oracle-tables where some of the PK-fields are defined as CHAR(9), and all values are stored with padding.

Thus, I have to retrieve all objects with space-padding in the key-fields. However, when EclipseLink reads the data into the object, the spaces are trimmed away. Since this occurs on the ID-values, there is no way for me to use @PostLoad in order to 'fix' the key so it will contain the spaces.

I have no way of deleting/updating the object since the key-value is changed to a trimmed value, and any update/delete misses on the key-value.

How can I configure my persistence-unit so it doesn't trim values for CHAR-columns ?


回答1:


You can use a SessionCustomizer to configure this,

public MyCustomizer implements SessionCustomizer {
  public customize(Session session) {
    session.getLogin().setShouldTrimStrings(false);
  }
}

But in general using CHAR instead of VARCHAR is normally a very bad idea.



来源:https://stackoverflow.com/questions/13352818/avoid-char-trimming-when-using-eclipselink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!