Hi,

This actually can happen dynamically in OpenJPA, but currently only if
you don't list any of your persistent types in persistence.xml.

I just created a test case to demonstrate this behavior; see the new
TestDynamicClassRegistration class.

In short, for enhanced classes, all you need to do is create a new
instance of the type and then start using it. You do need to create a
new instance before you can do things like issue queries that use
aliases. (Really, you just need to make sure that the static
initializer is called, so Class.forName(name, null, true) should be
enough.)

For unenhanced classes, you need to do a bit more work currently. From
the test case:

        // trigger class initialization
        ManagedClassSubclasser.prepareUnenhancedClasses(
            emf.getConfiguration(),
            Collections.singleton(UnenhancedFieldAccess.class),
            null);

It might be a good idea to create a new
OpenJPAEntityManagerFactory.registerTypes(Class...) method that will
take the appropriate steps for the supplied types, or throw an
exception if the current EMF doesn't support dynamic registration.

-Patrick

On Nov 15, 2007 11:10 AM, Alexandros Karypidis <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I use OpenJPA in a non-J2EE application, where I create my
> EntityManagerFactory programmatically. How do I add classes to OpenJPA's
> configuration? I am looking for something similar to Hibernate's
> Ejb3Configuration.addAnnotatedClass() method.
>
> Thanks.
>
>



-- 
Patrick Linskey
202 669 5907

Reply via email to