What about having all of your entities extend from a common superclass
that defines a getter for the pk?
For instance, for many applications, I use a simple int primary key,
so my entities all extend from a common superclass, with a method ala:
public int getPK() {
return DataObjectUtils.intPKForObject(this);
}
Or even:
public Object getPK() {
return DataObjectUtils.pkForObject(this);
}
to be more general.
Or you could use generics:
public <T> T primaryKey(Class<T> type) {
return type.cast(DataObjectUtils.pkForObject(this));
}
and have all sorts of fun with wrappers, like:
public Integer intPK() {
return primaryKey(Integer.class);
}
Cheers,
Robert
On Jan 22, 2009, at 1/221:47 PM , wwwebi wrote:
> Hi,
>
> is there a possibility to create for all objects a getter method on
> the primary key fields within the process of reverse engineering ?
>
> I have a legacy database where the primary keys are used in a
> similar way as a passport no and as I need it for 100+ tables I
> wondered if I could not at least get a getter method of the primary
> key fields during reverse engineering. Setting it afterwards
> following this faq http://cwiki.apache.org/CAY/mapping-primary-keys.html
> is too time consuming. I don't see even an issue only with a getter
> method.
>
> If it's not possible within the modeler I would certainly like to
> see this as an option during reverse engineering in the future :-)
>
> Cheers,
> Martin
This archive was generated by hypermail 2.0.0 : Thu Jan 22 2009 - 15:01:37 EST