openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Dick" <michael.d.d...@gmail.com>
Subject Re: Programmatical EntityManagerFactory init
Date Fri, 06 Apr 2007 14:05:57 GMT
Hi Erwan,

What do you have in persistence.xml?

It should contain something like this :

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="1.0">

    <persistence-unit name="teamplay_test">
    . . .
    </persistence-unit>
</persistence>

One thing to watch out for is if you've defined a provider inside the
persistence unit. If that is the case the provider needs to be
org.apache.openjpa.persistence.PersistenceProviderImpl (assuming you want to
use OpenJPA).

If persistence.xml does contain the persistence unit then I'm not sure what
would cause the problem. Maybe a classpath issue?

-Mike

On 4/6/07, Erwan Le Goulven <erwan.legoulven@gmail.com> wrote:
>
> Messieurs-dames,
>
> As I could not find much clues about the right way to do it, here I come:
> I'm trying to get an EntityManagerFactory properly setup from the
> Persistence class, but I cannot get further than the following exception
>
> javax.persistence.PersistenceException: No Persistence provider for
> EntityManager named teamplay_test
>     at javax.persistence.Persistence.createEntityManagerFactory(
> Persistence.java:89)
>     at com.gdteam.teamplay.domain.manager.TeamplayEMFactoryManager.get (
> TeamplayEMFactoryManager.java:60)
>     at com.gdteam.teamplay.test.persistence.PersistenceUtilTest.setUp(
> PersistenceUtilTest.java:19)
>     at junit.framework.TestCase.runBare(TestCase.java:125)
>     at junit.framework.TestResult$1.protect (TestResult.java:106)
>     at junit.framework.TestResult.runProtected(TestResult.java:124)
>     at junit.framework.TestResult.run(TestResult.java:109)
>     at junit.framework.TestCase.run(TestCase.java:118)
>     at junit.framework.TestSuite.runTest(TestSuite.java:208)
>     at junit.framework.TestSuite.run(TestSuite.java:203)
>
> Here is the code part that leads to the exception:
>
> public class TeamplayEMFactoryManager  {
> ...
>     private final Map<String, String> props = new HashMap<String,
> String>();
>     private final Map<String, EntityManagerFactory> map = new
> HashMap<String, EntityManagerFactory>();
> ...
>     private TeamplayEMFactoryManager() {
>         props.put("openjpa.ConnectionDriverName", "org.hsqldb.jdbcDriver
> ");
>         props.put("openjpa.ConnectionUserName", "sa");
>         props.put("openjpa.ConnectionPassword", "");
>         props.put("openjpa.Log", "DefaultLevel=WARN, Tool=INFO");
>         props.put("openjpa.MetaDataFactory",
> "jpa(Types="+buildTypes()+")");
>
>     }
>
> ..
>
> public EntityManagerFactory get(String url) {
>
>         EntityManagerFactory factory = null;
>
>         if (null == url || url.length() == 0 ) {
>             url = "default";
>         }
>
>         factory = this.map.get(url);
>
>         if (null == factory) {
>             if ( "default".equals(url)) {
> 1-               factory = Persistence.createEntityManagerFactory(null);
>             } else {
>                 Map<String , String> map = new HashMap<String,
> String>(props);
>                 map.put("openjpa.ConnectionURL ", buildUrl(url));
> 2-              factory = Persistence.createEntityManagerFactory(url,map);
>             }
>             this.map.put(url, factory);
>         }
>         return factory;
>     }
> ...
> }
>
>
> Note :
> I'm using a persistence.xml for single persitence unit creation, and this
> test works fine. I've had a dive into the source code, and found the
> provider is lookuped and found by the glassfish persistence implementation
> class. The exception is raised on the open jpa side, and I know I'm
> missing
> some configuration elements, but I cannot guess what's missing?
> any hint?
>
> thank you guys
>

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