OJB参考描述符1:0关系?我应该将自动检索设置为 false 吗?
我在 Web 应用程序中使用 Apache OJB 和 Spring 2 时遇到问题。
我正在使用带有 2 个外键属性的 OJB 引用描述符。我有一个对象 A (父对象)和对象 B (引用对象)。问题是,对于一个对象 A,可能有也可能没有对象 B。
在没有对象 B 与对象 A 一起使用的情况下,对象 B 似乎无论如何都被实例化了(通过 Spring?)。但是,我无法访问对象 B 的成员。
每当我测试 Object B == null 时,即使数据库中没有匹配的值,它也总是返回 false。
由于这个对象永远不会为空,我想我可以像这样测试对象的成员:
if( objectb.getDocumentNumber == null) { return false; }但是
,我在 jsp 中遇到异常:
javax.servlet.jsp.el.ELException: An error occurred while getting property
"documentNumber" from an instance class
org.sample.pojo.Objectb$$EnhancerByCGLIB$$78022a2
并且在调试器创建 objectB 时出现此异常:
com.sun.jdi.InvocationException occurred invoking method.
我猜测引用描述符必须是 1:1+ 关系,而不是 1:0+ 关系。我想知道是否应该将属性“自动检索”设置为 false,然后使用 PersistenceBroker.retrieveAllReferences(Object obj);按照指示的方法。然而,这个方法的返回值是“void”,所以我猜测 Spring 以某种方式为我创建并设置了引用类。 (让我回到我遇到的同一问题。)
我需要一种方法来首先测试引用对象是否存在。如果没有,请不要调用此retrieveAllReferences方法,但我不知道如何调用。
我这一切都错了吗?引用描述符不允许 1:0 关系吗? 有办法解决我的问题吗?
非常感谢您的建议!
I am having an issue while using Apache OJB with Spring 2 inside my web app.
I'm using OJB reference-descriptor with 2 foreign key properties. I have an object A (parent) and object B (referenced object). The thing is, for an object A, there may or may not be an object B.
In the case where there is no object B to go with Object A, the object B seems to be instantiated (through Spring?) anyways. However, I am unable to access object B's members.
Whenever I test if Object B == null, it always returns false even though there is no matching value in the database.
Since this Object is never null, I figured I can test the object's member like so:
if( objectb.getDocumentNumber == null) { return false; }
However, I get an exception in the jsp:
javax.servlet.jsp.el.ELException: An error occurred while getting property
"documentNumber" from an instance class
org.sample.pojo.Objectb$EnhancerByCGLIB$78022a2
and this exception in the debugger when it's creating the objectB:
com.sun.jdi.InvocationException occurred invoking method.
I am guessing that the reference-descriptor must be a 1:1+ relationship, instead of a 1:0+
relationship. I was wondering if I should set the property 'auto-retrieve' to false, and then use the PersistenceBroker.retrieveAllReferences(Object obj); method as directed. However, this method's return value is 'void', so I am guessing that Spring somehow creates, and sets the reference class for me. (Returning me back to the same issue I'm having.)
I will need a way to test whether the reference object exists first. If not, don't call this retrieveAllReferences method, but I don't see how.
Am I going about this all wrong? Does reference-descriptor not allow 1:0 relations?
Any work around to my problem?
Your suggestions are greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。为了防止它对其他人有帮助,我设置 proxy = false。
这对我有用,因为通过将其设置为 false,它不会创建临时引用对象,并且我可以用它来测试 null。
无论如何,谢谢。
I figured it out. Just in case it will help anyone else, i set proxy = false.
This works for me, because by setting it to false, it won't create a temporary reference object, and I could test for null with that.
Thanks anyways.