Hi I am new to Hibernate JPA. I am using eclipse kepler 4.3.2 and create a simple java project. I am not using maven to compile the project. I am having the below persistence.xml located in the src folder of the project
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" >
<persistence-unit name="rawsjpa" transaction-type="RESOURCE_LOCAL">
<!-- <class>com.mumz.test.hibernatesearch.entitybeans.MHSBookEntityBean</class>
<class>com.mumz.test.hibernatesearch.entitybeans.MHSBookShelfEntityBean</class> -->
<properties>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.password" value="Test2@cdn"/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=rschcdndb1d.nam.nsroot.net)(PORT=1526))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=OSRDD1)))"/>
<property name="hibernate.connection.username" value="AW"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle8iDialect"/>
</properties>
</persistence-unit>
</persistence>
I am having the below sample main program trying to create the EntityManager.
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
/**
*
*/
/**
* @author jp48346
*
*/
public class TestRawsConnection {
public static void main(String args[]){
EntityManager entityManager = Persistence.createEntityManagerFactory("rawsjpa").createEntityManager();
if(entityManager!=null){
System.out.println("************* EntityManager is obtained *****************");
}
}
}
Below is the eclipse project .classpath file
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="main/resources/META-INF/" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/org/hibernate/hibernate-entitymanager/4.2.17.Final/hibernate-entitymanager-4.2.17.Final.jar"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.2.Final/hibernate-commons-annotations-4.0.2.Final.jar"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.0-api/1.0.1.Final/hibernate-jpa-2.0-api-1.0.1.Final.jar"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/org/hibernate/hibernate-core/4.2.17.Final/hibernate-core-4.2.17.Final.jar"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/org/jboss/logging/jboss-logging/3.1.0.GA/jboss-logging-3.1.0.GA.jar"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/javax/transaction/jta/1.1/jta-1.1.jar"/>
<classpathentry kind="lib" path="C:/Users/jp48346/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
when I am trying to execute the program I am getting the below exception
May 26, 2015 8:52:17 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.2.Final}
May 26, 2015 8:52:18 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.2.17.Final}
May 26, 2015 8:52:18 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
May 26, 2015 8:52:18 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
May 26, 2015 8:52:18 PM org.hibernate.ejb.Ejb3Configuration configure
INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named rawsjpa
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at TestRawsConnection.main(TestRawsConnection.java:15)
Can anybody please tell me where should I place persistence.xml to resolve the above issue?
the persistence.xml file should reside in a folder named META-INF
. If you are using using Maven, put it in src/main/resources/META-INF
(create the folder if it's not there).