db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <tom...@gmail.com>
Subject Re: Inheritance using special attribute ojbConcreteClass issue
Date Tue, 25 Oct 2005 22:36:34 GMT
On 10/25/05, Bernd Laengerich <B.Laengerich@actosoft.de> wrote:
> Hi,
>
> is there any way to tell OJB to use a different attribute name for a
> specific class instead of ojbConcreteClass?
>
> The problem is, I have a table A with objects of two different classes
> A und B (both using inheritance) instantiated from it.
>
> Torque refuses the "datasql" target with the error:
> Attribute "OjbConcreteClass" was already specified for element "ATABLE".
> OJB itself is working fine with it.

I think the error comes from the XDoclet module, not from Torque.
The problem is that you should not redefine the field in the subclass
(you don't have to, anyway, as its protected and thus already visible
in the subclass), because when using reflection there is no guarantee
which one (of the base class or the sub class) is used.
The usual pattern is to define the field in the base class, and
initialize it either directly on in the constructor, like so:

private String ojbConcreteClass = getClass();

Btw, this way you don't even have to make it protected as the
subclasses don't do much with it anyway.

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Mime
View raw message