У меня проблема с настройкой Tomcat 8.0 с JPA с использованием Hibernate в качестве провайдера в Eclipse. Когда я пытался использовать аннотацию DataSource и стандартный способ JDBC для подключения к БД, соединение в порядке, но когда я пытаюсь использовать Hibernate, я получаю исключение о том, что для моего PU нет провайдера. Я пытался переместить библиотеки гибернации во многие каталоги (web-inf/lib, библиотека apache TC), но все равно получаю то же исключение. Я думаю, что источник данных настроен правильно. Ниже я добавляю свои настроенные файлы.
веб.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/HibernateTest" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="admin" password="admin" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/Hibernate"/>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
1.xsd"
id="WebApp_ID" version="3.1">
<display-name>HibernateTest</display-name>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/HibernateTest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
постоянство.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="HibernateTest" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/HibernateTest</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
</persistence>
context.xml в tomcat (только фрагмент)
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/HibernateTest" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="admin" password="admin" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/Hibernate"/>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("HibernateTest");
EntityManager em = emf.createEntityManager();
em.close();
emf.close();
}
} `
jta-data-source
вcontext.xml
сjava:comp/env/
. - person Mehrdad Nurolahzade   schedule 12.02.2016