Hibernate 可以将 Null String 默认为 Empty String
在我们的应用程序中,我们从 DB2 大型机数据库中提取数据。如果数据库的字段中有“低值”,hibernate 会在对象中发送“空”值。即使该列被定义为“not null”,也会发生这种情况。
当我们对此进行 XML 解析时,Castor 遇到了麻烦。我想在 Hibernate 中解决这个问题。另外,所有的 hibernate hbm 文件都已生成,因此我们不能弄乱它们(它们会不时重新生成。)
有什么方法可以拦截所有字符串并用 ""
替换 null 吗?
In our application we are pulling data from a DB2 mainframe database. If the database has "low values" in a field, hibernate sends a "null" value in the object. This occurs even if the column is defined as "not null".
As we are doing XML parsing on this, Castor is having trouble with it. I would like to fix this in Hibernate. Also, all of the hibernate hbm files are generated, so we can't mess with them (they are regened from time to time.)
Any way to intercept all Strings and replace nulls with ""
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
null
替换为""
reveng.xml
中通常放置 hibernate 类型名称的位置。null
with""
reveng.xml
.这是我们的解决方案(归功于 @Betlista 和 @markthegrea)想出了。实际上,这是一个大写字母并被截断(许多抽象方法被删除)。
然后你这样连接它:
Here is the Solution we (credits to @Betlista and @markthegrea) came up with. Actually, this is an upper case one and is truncated (lots of abstract methods are removed).
And then you hook it up this way:
您可以使用 hibernate 拦截器扩展 EmptyInterceptor 在实际触发该查询之前执行您想要的操作。
此处给出的示例可能会帮助您
http://www.mkyong。 com/hibernate/hibernate-interceptor-example-audit-log/
You can use hibernate interceptor which extends EmptyInterceptor to perform the operation you want to before actually firing that query.
the example given here might help you
http://www.mkyong.com/hibernate/hibernate-interceptor-example-audit-log/
我通过在连接器设置器中处理数据库 NULL 值来解决同样的问题,就像此处建议的那样,使用一个简单的方法
I solve same issue on my side by handling database NULL values in the connector setters, like advised here, with a simple