openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: FieldMetaData questions
Date Tue, 10 Mar 2009 16:00:09 GMT
Hi Heather.

Most of the info you want is already there in the FieldMapping /
FieldMetaData. It's just a matter of digging :-).

On Tue, Mar 10, 2009 at 10:09 AM, Heather Sterling <>wrote:

> Hi,
> I was wondering how to retrieve the possible enum values from a
> FieldMetaData structure.

Something like this should work :

        ClassMetaData meta = JPAFacadeHelper.getMetaData(emf,
        FieldMetaData fmd = meta.getField("myEnum");

        Object [] enums = fmd.getType().getEnumConstants();
        for(Object o : enums ) {
            // do whatever you need to with the constants.
            System.out.format("%s%n", o);

I also wanted to know if there's a way to get other information, such as
> the length of a field. (specified with @Column annotation).  I assume there
> is, but I could not find it.

Here you need the FieldMapping, not the metadata. From the mapping you can
get the columns, and from there the size.

        ClassMetaData meta = JPAFacadeHelper.getMetaData(emf,
        FieldMetaData fmd = meta.getField("name");


        FieldMapping fm = (FieldMapping) fmd;
        Column[] cols = fm.getColumns(); //
        // @Column(length=32). Happens to be a string, but this should work
for other types.
        assertEquals(32, cols[0].getSize());

Lastly, is there a way to extend the metadata, such that I could tag a
> field with a custom-defined property-value pair and retrieve it?  I saw
> that there are some extension APIs on FieldMetaData, but I'm not sure what
> the purpose of those are.  For example, in our current legacy code, we have
> the idea of a "hidden" property.  I would like to be able to retrieve this
> when looping through the fields in order to correctly transform the data to
> our existing legacy structures.

I'm not sure. I'd need to look at it more. Maybe someone else on the list
has a quick answer, or more experience in this area.

Hope this helps

> Thanks,
> Heather Sterling
> Systems Management Development
> Phone:  919-254-7163 T/L: 444-7163
> Cell: 919-423-3143
> Email:

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message