openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Bauer <techhu...@gmail.com>
Subject Re: metadata api?
Date Wed, 09 Sep 2009 14:41:45 GMT
Hi Chris,

OpenJPA provides APIs that allow you to interrogate class mappings.  Using a
direct approach (OpenJPA resolves class mapping and metadata as part of
creating an emf/em), this code gives you access to the primary and foreign
keys of an entity via the schema information stored in the mapping.

import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.ForeignKey;
import org.apache.openjpa.jdbc.schema.PrimaryKey;
import org.apache.openjpa.persistence.JPAFacadeHelper;

...
        EntityManager em = emf.createEntityManager();
        ClassMapping clsMapping =
(ClassMapping)JPAFacadeHelper.getMetaData(em, SomeEntity.class);

        ForeignKey[] fks = clsMapping.getTable().getForeignKeys();
        PrimaryKey pk = clsMapping.getTable().getPrimaryKey();

hth,
-Jeremy

On Wed, Sep 9, 2009 at 3:31 AM, Christopher Giblin <CGI@zurich.ibm.com>wrote:

>
> Hi,
> I defined object-relational mappings in orm.xml.  Works fine.
>
> Is an API available which allows querying of the orm definition for a given
> object? I am programming with reflection and would like to know, given an
> object, which of its attributes are primary or foreign keys.
>
> Thanks, chris
>
>

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