Create persistence unit programmically without persistence.xml

View: New views
3 Messages — Rating Filter:   Alert me  

Create persistence unit programmically without persistence.xml

by philk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I want to create a persistence unit with out using the persistence.xml. I am already feeding EL all the "eclipselink" properties for the database connection and the class loader. The last thing I struggle to find is, how to feed EL the entity classes that the PU should be aware of. How would I do that?

Thanks,
Phil

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Create persistence unit programmically without persistence.xml

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I suppose that is the main reason you need a persistence.xml, to define the set of classes/classpath.  I don't think it is possible to deploy JPA without a persistence.xml.  You could log an enhancement to allow passing the class list, or orm.xml file with the persistence properties Map, but you would still need to access the EclipseLink provider directly as JPA Persistence requires a persistence.xml to know the provider.

You can create an EntityManagerFactory using an EclipseLink ServerSession, but then you would need to build the EclipseLink ClassDescriptors yourself or using the Mapping Workbench.  You could also try to use the MetadataProcessor directly yourself to process a set of annotations or orm.xml.


philk wrote:
Hello,

I want to create a persistence unit with out using the persistence.xml. I am
already feeding EL all the "eclipselink" properties for the database
connection and the class loader. The last thing I struggle to find is, how
to feed EL the entity classes that the PU should be aware of. How would I do
that?

Thanks,
Phil

Re: Create persistence unit programmically without persistence.xml

by philk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

James Sutherland wrote:
> I suppose that is the main reason you need a persistence.xml, to define the
> set of classes/classpath.  I don't think it is possible to deploy JPA
> without a persistence.xml.  You could log an enhancement to allow passing
> the class list, or orm.xml file with the persistence properties Map, but you
> would still need to access the EclipseLink provider directly as JPA
> Persistence requires a persistence.xml to know the provider.

Well in the good old days of Hibernate I could just create a session and
add my classes to it on the fly. Seems that never made it into SUNs JPA
specs. However I have completely removed the provider from the
persistence.xml and hand it to EL using the properties of the EMF. This
seems to work ok. The only thing left in the persistence.xml is the spec
of the classes. I guess it would not be too hard to expose the method
that parses the classname in EL and creates the ClassDescriptor for it
as a public method of the EL JPA Provider.

Still, JPA inside a dynamic OSGi environment is painful. Hibernate was
much more flexible even 4 years ago.

> philk wrote:
>> Hello,
>>
>> I want to create a persistence unit with out using the persistence.xml. I
>> am
>> already feeding EL all the "eclipselink" properties for the database
>> connection and the class loader. The last thing I struggle to find is, how
>> to feed EL the entity classes that the PU should be aware of. How would I
>> do
>> that?
>>
>> Thanks,
>> Phil
>>
>>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users