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.