Hi Tim,
Tim Hollosy wrote:
Thanks Dough & Shaun,
The properties map worked fine, the only issue we had was using:
<persistence-unit name="unit-name">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>
With that set, I cannot create an Entity Manager, I get an error
saying it can't find the database driver (PostgreSQL), however if I
just define my classes in my persistence.xml like this:
<persistence-unit name="unit-name">
<class>org.bla.bla.Table</class>
<class>org.bla.bla.Table</class>
</persistence-unit>
It works fine.
Why you can't find your driver is a mystery but I think you're running
into some issues due to classloader
behavior in Equinox. I hadn't tried any examples with
<exclude-unlisted-classes>false</exclude-unlisted-classes>
but as I learn more I see this may require special support. This is
something we'll have to look into once we get the main branch switched
over to OSGi.
On top of that, it will only work if I create my Entity Manager like this:
emf = new PersistenceProvider().createEntityManagerFactory("unit-name",
properties,this.getClass().getClassLoader());
If I try to do it like in the examples, using the static method:
emf = Persistence.createEntityManagerFactory("unit-name", properties);
It will not work, throwing a PersistenceException "No Persistence
provider for EntityManager named unit-name".
In the Proof of Concept there are three
ways to create an EntityManagerFactory. The one you're using is
the easiest in that it passes the classloader that can load all the
necessary classes directly to the EclipseLink persistence provider and
avoids the need for javax.persistence.Peristence to locate it. If you
want to invoke Persistence.createEntityManagerFactory you'll need to
follow the steps outlined on the section Creating a JPA application bundle using the
standard JPA SPI. When doing this you have to make sure you
have the start levels set so that EclipseLink JPA is initialized
before you try to use it in application code.
I can mostly live with creating my em the other way, however it would
be nice to get auto discovery of classes to work.
I'm working on it in conjunction with enabling byte code weaving in
Equinox. ;-) This is a ways off so hopefully you can live with listing
the classes for now. I expect we'll see a big improvement in the ease
of use as we transition over to OSGi in EclipseLink and we get more
experience with it.
--Shaun
Thanks again,
Tim
On Mon, Mar 31, 2008 at 12:43 PM, Doug Clarke <douglas.clarke@xxxxxxxxxx> wrote:
Tim,
You can definitely avoid putting any database login information in your EclipseLink configuration files. I have recently blogged about a common framework I use for testing JPA outside of a container. This will work as well for any JavaSE or RCP application usage where the additional properties are passed in through a properties map to the Persistence.createEntitymanagerFactory call.
http://java-persistence.blogspot.com/2008/02/testing-eclipselink-jpa-in-javase.html
On Friday night I moved some of this content into the EclipseLink wiki example pages to make it more available.
http://wiki.eclipse.org/EclipseLink/Examples/JPA/OutsideContainer
I hope this addresses your issue,
Doug
-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx
[mailto:eclipselink-users-bounces@xxxxxxxxxxx]On Behalf Of Tim Hollosy
Sent: Monday, March 31, 2008 11:49 AM
To: eclipselink-users@xxxxxxxxxxx
Subject: [eclipselink-users] Defining persistence.xml programatically?
I'm looking into using EclipseLink in an RCP application, and for
obvious reason's i'm not keen on distributing my database login info
in an xml file.
I'd like to define it programatically in java, however all the
documentation I can find just talks about defining a project.xml or
sessions.xml
Has anyone done this?
--
./tch
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--
Shaun Smith | Principal Product Manager, TopLink |
+1.905.502.3094
Oracle Fusion Middleware
110 Matheson Boulevard West, Suite 100
Mississauga, Ontario, Canada L5R 3P4
|