每次我尝试在 OpenShift 上访问我的应用程序时,都会收到“No Persistence provider for EntityManager named appname”错误。
我连续两天一直在努力解决这个问题,但我仍然没有找到答案。
我已经尝试了我在网上找到的所有可能的配置。
我目前的配置:
META-INF\persistence.xml
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/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">
<persistence-unit name="appname" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/comp/env/jdbc/appname</jta-data-source>
<class>myorg.mypackage.MyClass</class>
<properties>
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory" />
</properties>
</persistence-unit>
</persistence>
.openshift\config\context.xml
<Context>
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/appname" password="mypass"
type="javax.sql.DataSource" url="jdbc:mysql://myurl:3306/appname"
username="myuser" />
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
.openshift\config\server.xml
<Host name="localhost" appBase="webapps" unpackWARs="false" autoDeploy="true">
<Context docBase="appname" path="/appname" reloadable="true" source="org.eclipse.jst.jee.server:appname" />
</Host>
例外
javax.persistence.PersistenceException: No Persistence provider for EntityManager named appname
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at org.andvicoso.shopand.model.dao.base.GenericDaoJPA.<init>(GenericDaoJPA.java:20)
at org.andvicoso.shopand.model.dao.ProductDaoJPA.<init>(ProductDaoJPA.java:8)
at org.andvicoso.shopand.web.ViewHelper.getProductDao(ViewHelper.java:31)
at org.andvicoso.shopand.web.ViewHelper.getHighlights(ViewHelper.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:87)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:106)
at org.apache.jsp.index_jsp._jspx_meth_c_005fset_005f6(index_jsp.java:260)
谁能帮我???
提前致谢。