每次我尝试在 OpenShift 上访问我的应用程序时,我都会收到“没有名为 appname 的 EntityManager 的持久性提供程序”错误。
我连续两天都在努力解决这个问题,但我仍然没有找到答案。
我已经尝试了我在网上找到的所有可能的配置。
我当前的配置:
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)
谁能帮帮我???
提前致谢。
最佳答案
我遇到了这个问题,发现我的 META-INF 在 src\main\java 下导致了这个错误。当我将 META-INF 移动到 src\main\resources 时...它起作用了。
关于mysql - Tomcat 7 (JBoss EWS 2.0) + MySQL 5.1 + Hibernate - OpenShift - 未找到持久性单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15956163/