Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Defining persistence.xml programmatically?

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.

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".

I can mostly live with creating my em the other way, however it would
be nice to get auto discovery of classes to work.

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
>



-- 
./tch


Back to the top