0 and Tomcat8. So I have created one web project in eclipse. Firstly I have create one context.xml file and put it into META-INF folder inside web-content folder. It looks like this...
<context>
<Resource name="jdbc/myDataSource" auth="Container" type="javax.sql.DataSource"
maxActive="50" maxIdle="30" maxWait="10000" username="postgres"
password="password" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/test" />
</Context>
Then create one entry into web.xml file.
<resource-ref>
<description>postgres Datasource example</description>
<res-ref-name>jdbc/myDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
I want to create the EntityManagerFactory instance on application start so i also added one listener entry into web.xml file.
<listener-class>com.listener.initlization.PersistenceListener</listener-class>
Now implement ServletContextListener to create EntityManagerFactory like this
@Override
public void contextInitialized(ServletContextEvent evt) {
ServletContext ctxt = evt.getServletContext();
entityManagerFactory = Persistence
.createEntityManagerFactory("test");
}
I am also putting one image which will tell you about the library and structure of them.
now finally persistence.xml file looks like this.
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:comp/env/jdbc/myDataSource</non-jta-data-source>
<!-- <class>com.model.Employee</class> -->
<properties>
<!-- <property name="javax.persistence.jdbc.url" value="jdbc:postgres://localhost:5432/test" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="password" /> -->
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.connection.datasource" value="java:/comp/env/jdbc/myDataSource"/>
</properties>
</persistence-unit>
</persistence>
So Now problem is when application starts and comes to Listener it throws an error.
javax.persistence.PersistenceException: No Persistence provider for EntityManager named test.
Please let me know whats wrong in this program.