-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem bootstrapping EntityManagerFactory
PostPosted: Fri Dec 15, 2006 7:52 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
Hi,

I am having problems bootstrapping my EntityManagerFactory based on 2.2.2 in the manual. I have this code to check to see if my persistence.xml is in the path

Code:

    private void initializeFactory() {
        ClassLoader loader;
        Enumeration<URL> resources;
        URL resource;
        BufferedReader reader;
        Pattern nonCommentPattern = Pattern.compile("^([^#]+)");

        //get the current context class loader
        loader = Thread.currentThread().getContextClassLoader();
        //try to get the persistence.xml file
        try {
            //get the resource URLs
            resources = loader.getResources("META-INF/persistence.xml");
            //log them
            while (resources.hasMoreElements()) {
                //get the next url
                resource = resources.nextElement();
                //log the path
                log.warn("Path to persistence resource is #0", resource.getPath());
                //read in the file
                reader = new BufferedReader(new InputStreamReader(resource.openStream()));
                do {
                    String line;
                    if((line = reader.readLine()) == null)
                        break;
                    line = line.trim();
                    Matcher m = nonCommentPattern.matcher(line);
                    if(m.find())
                        log.warn("Persistence Unit name is #0", m.group().trim());
                } while(true);
            }
        } catch (IOException e) {
            log.error("", e);
        }

        log.info("Initializing factory");
        factory = Persistence.createEntityManagerFactory("indigoDatabase");
        log.debug("Factory " + factory);
    }



Here is the output. As you can see, it finds the persisence.xml in two places and displays the content. But, it still can't find the EntityManagerFactory. The exception follows:

[15:45:20.640] [WARN ] [DimensionTest] - Path to persistence resource is /target/test-classes/META-INF/persistence.xml
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <?xml version="1.0" encoding="UTF-8"?>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <persistence xmlns="http://java.sun.com/xml/ns/persistence">
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <persistence-unit name="indigoDatabase">
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <provider>org.hibernate.ejb.HibernatePersistence</provider>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <jta-data-source>java:/IndigoDS</jta-data-source>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <properties>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.hbm2ddl.auto" value="update"/>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.cache.use_query_cache" value="true"/>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.show_sql" value="true"/>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.cache.provider_class"
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is value="org.hibernate.cache.HashtableCacheProvider"/>
[15:45:20.656] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.dialect" value="org.hibernate.dialect.SAPDBDialect"/>
[15:45:20.671] [WARN ] [DimensionTest] - Persistence Unit name is <property name="com.intellij.javaee.persistence.datasource" value="Datasource"/>
[15:45:20.671] [WARN ] [DimensionTest] - Persistence Unit name is <property name="jboss.entity.manager.factory.jndi.name" value="java:/indigoEntityManagerFactory"/>
[15:45:20.671] [WARN ] [DimensionTest] - Persistence Unit name is </properties>
[15:45:20.671] [WARN ] [DimensionTest] - Persistence Unit name is </persistence-unit>
[15:45:20.671] [WARN ] [DimensionTest] - Persistence Unit name is </persistence>
[15:45:20.671] [WARN ] [DimensionTest] - Path to persistence resource is /target/classes/META-INF/persistence.xml
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <?xml version="1.0" encoding="UTF-8"?>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <persistence xmlns="http://java.sun.com/xml/ns/persistence">
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <persistence-unit name="indigoDatabase">
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <provider>org.hibernate.ejb.HibernatePersistence</provider>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <jta-data-source>java:/IndigoDS</jta-data-source>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <properties>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.hbm2ddl.auto" value="update"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.cache.use_query_cache" value="true"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.show_sql" value="true"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.cache.provider_class"
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is value="org.hibernate.cache.HashtableCacheProvider"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="hibernate.dialect" value="org.hibernate.dialect.SAPDBDialect"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="com.intellij.javaee.persistence.datasource" value="Datasource"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is <property name="jboss.entity.manager.factory.jndi.name" value="java:/indigoEntityManagerFactory"/>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is </properties>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is </persistence-unit>
[15:45:20.687] [WARN ] [DimensionTest] - Persistence Unit name is </persistence>
[15:45:20.703] [INFO ] [DimensionTest] - Initializing factory
javax.persistence.PersistenceException: No Persistence provider for EntityManager named indigoDatabase
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.intava.indigo.ejb.metacube.DimensionTest.initializeFactory(DimensionTest.java:123)

Does anybody know what is going wrong here. I am using hibernate 3.2.0.GA. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 03, 2007 8:25 pm 
Regular
Regular

Joined: Thu Jul 29, 2004 11:55 pm
Posts: 75
I discovered the problem. There were two issues.

1) I was still defining the jta-datasource
2) i didn't have the entitymanager jar in my path

The second one was the hardest to track down. I would have been nice if the error message stated that it could not find the specified <provider> instead of javax.persistence.PersistenceException: No Persistence provider for EntityManager named indigoDatabase. This would have made the problem very easy to solve.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.