使用eclipselink时避免进行CHAR修饰 [英] Avoid CHAR-trimming when using eclipselink

查看:107
本文介绍了使用eclipselink时避免进行CHAR修饰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Oracle表,其中某些PK字段定义为CHAR(9),所有值都用填充存储.

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

因此,我必须在键字段中检索所有带有空格填充的对象. 但是,当EclipseLink将数据读入对象时,空格将被修剪掉.由于这是在ID值上发生的,因此我无法使用@PostLoad来修复"密钥,使其包含空格.

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.

如何配置我的持久性单元,这样它就不会修剪CHAR列的值?

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

推荐答案

您可以使用SessionCustomizer对其进行配置,

You can use a SessionCustomizer to configure this,

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

但是通常使用CHAR而不是VARCHAR通常是一个非常糟糕的主意.

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

这篇关于使用eclipselink时避免进行CHAR修饰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆