OJB参考描述符1:0关系?我应该将自动检索设置为false吗? [英] OJB Reference Descriptor 1:0 relationship? Should I set auto-retrieve to false?

查看:76
本文介绍了OJB参考描述符1:0关系?我应该将自动检索设置为false吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中使用带有Spring 2的 Apache OJB 时,我遇到了问题.

I am having an issue while using Apache OJB with Spring 2 inside my web app.

我正在使用具有2个外键属性的OJB参考描述符.我有一个对象A(父对象)和对象B(引用对象).问题是,对于对象A,可能存在或可能不存在对象B.

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.

在没有对象B与对象A一起使用的情况下,无论如何,对象B似乎都已实例化(通过Spring?).但是,我无法访问对象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.

每当我测试对象B == null时,即使数据库中没有匹配的值,它总是返回false.

Whenever I test if Object B == null, it always returns false even though there is no matching value in the database.

由于此Object永远不会为null,所以我认为可以像这样测试该对象的成员:

Since this Object is never null, I figured I can test the object's member like so:

if(objectb.getDocumentNumber == null){返回false; }

if( objectb.getDocumentNumber == null) { return false; }

但是,我在jsp中遇到一个异常:

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

以及调试器在创建objectB时的以下异常:

and this exception in the debugger when it's creating the objectB:

com.sun.jdi.InvocationException occurred invoking method.

我猜测引用描述符必须是1:1+关系,而不是1:0+ 关系.我想知道是否应该将属性自动检索"设置为false,然后使用PersistenceBroker.retrieveAllReferences(Object obj);.按照指示的方法.但是,此方法的返回值为'void',因此我猜测Spring会以某种方式创建并为我设置引用类. (让我回到遇到的同一问题.)

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.)

我将需要一种方法来测试参考对象是否首先存在.如果没有,请不要调用此retrieveAllReferences方法,但是我不知道如何.

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.

我要把这全部弄错了吗?参考描述符不允许1:0关系吗? 有什么办法解决我的问题吗?

Am I going about this all wrong? Does reference-descriptor not allow 1:0 relations? Any work around to my problem?

非常感谢您的建议!

推荐答案

我知道了.为了以防万一,对其他人有帮助,我将proxy设置为false.

I figured it out. Just in case it will help anyone else, i set proxy = false.

这对我有用,因为将其设置为false不会创建临时引用对象,我可以用它来测试null.

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.

还是谢谢.

这篇关于OJB参考描述符1:0关系?我应该将自动检索设置为false吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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