Hello; I asked this question before and got crickets.

What is the best way to customize a ReverseMappingTool run such that for
every table mapped I create a MappedSuperclass that it inherits from?

I am using OpenJPA 1.2.1 and generating annotations, not XML.

So if I have a database table named Person, then I want a
PersonMappedSuperclass.java and a Person.java class that inherits from it.

I am so close it is maddening, but cannot cross the final chasm.

The first thing I do is to set my ReverseCustomizer to change the incoming
ClassMapping to setEmbeddedOnly(true), and rename it to
xyzMappedSuperclass.  Then I generate a new class, set the MappedSuperclass
as its parent, and install the new mapping directly into the repository,
like so (inside customize(ClassMapping)):

    mapping.setEmbeddedOnly(true);

    final Class<?> mappingClass = mapping.getDescribedType();
    final String mappingClassName = mappingClass.getName();

    final String newClassName = mappingClassName.substring(0,
mappingClassName.length() - "MappedSuperclass".length());
    final Class<?> newClass = this.tool.generateClass(newClassName,
mappingClass);

    final MappingRepository mappingRepository = this.tool.getRepository();

    final ClassMapping newMapping =
(ClassMapping)mappingRepository.addMetaData(newClass);
    newMapping.setPCSuperclass(mappingClass);
    newMapping.setTable(mapping.getTable()); // ? maybe?
    newMapping.setEmbeddedOnly(false);

This does more or less what I want: at the end of this run, I get a mapped
superclass and an entity class that extends from it.  However, none of the
mapped superclass field information is filled in.  That is, I get things
like:

    @Basic

Instead of

    @Basic
    @Column(name="pmt_no", length=16)

Bug 1360 seems to be related to this (
http://issues.apache.org/jira/browse/OPENJPA-1360).  It would appear that in
the 1.2.x line, anyhow, it is impossible to create a MappedSuperclass whose
field annotations are properly filled in, thus of course defeating the
entire purpose of a MappedSuperclass.  I would be interested to learn if
ANYONE has ever generated MappedSuperclasses using this tool.

Best,
Laird

Reply via email to