public abstract class BaseDao<T> implements Serializable {
private static final long serialVersionUID = 1L;
//the next line is #18
private static final EntityManagerFactory emf = Persistence.createEntityManagerFactory("E_GYM");
public class TechniqueService implements Serializable {
private static final long serialVersionUID = -853877188695729368L;
private TechniqueDao techniqueDao = new TechniqueDao();
public TechniqueService() {}
//CRUD service methods...
}
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd“>
<persistence-unit name="E_GYM" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/e_gym" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.connection.shutdown" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
但面对这个例外:
java.lang.ClassNotFoundException: javax.persistence.Persistence
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at nassar.apps.orm.dao.BaseDao.<clinit>(BaseDao.java:18)
at nassar.apps.gym.services.TechniqueService.<init>(TechniqueService.java:12)
at nassar.apps.gym.views.TechniquesView.getTechniqueService(TechniquesView.java:90)
at nassar.apps.gym.views.TechniquesView.fillTechniques(TechniquesView.java:41)
at nassar.apps.gym.views.TechniquesView.<init>(TechniquesView.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
at org.apache.el.parser.AstValue.getValue(AstValue.java:160)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:732)
at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:1002)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:629)
at javax.faces.component.UIData.getRowCount(UIData.java:356)
at org.primefaces.component.api.UIData.calculateFirst(UIData.java:175)
at org.primefaces.component.datatable.DataTableRenderer.preRender(DataTableRenderer.java:110)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
任何帮助都将不胜感激...
谢了伙计们。我发现了错误。我将hibernate JAR分组到lib中的一个文件夹中,如下所示。
webcontent/web-inf/lib/hibernate-2/[所有必需的jar列表],如下所示
因此,将JAR直接移到lib文件夹下解决了这个问题。或者,我认为从项目属性将hibernate文件夹添加到Deployment Assemply中也可以解决这个问题。
在IBM WebSphere application Server was 7中启动EJB应用程序时,我遇到了以下错误。 JPAPUnitInfo E CWWJP0015E:org.hibernate.ejb.HibernatePersistence 持久性提供程序在尝试为 *YOUR_PERSISTENCE_UNIT* 持久性单元创建容器实体管理器工厂时出错。出现以下错误: [持久性单位: *Y
问题内容: 一个很长的问题,请忍受我。 我们将Spring + JPA用于Web应用程序。我的团队在讨论如何在注入的(基于泛型的东西对AppFuse中提供的线DAO,我们不使用过的注射某种原因)。我们正在使用“应用程序管理的持久性”。 反对注入a的论点是它太重了,因此不是必需的,这就是我们需要的。而且,由于Spring将为每个Web请求创建一个DAO的新实例(我对此表示怀疑),因此不会有任何并发
问题内容: 我在META-INF /文件夹中有一个persistence.xml: 在Java代码中,我从该persistence.xml创建实体管理器facotry 但是我只想动态更改jdbc url / user / password以进行测试,我的计划是将这些参数保存在配置文件中,并根据需要读取它们,所以有没有一种方法可以在我从持久性创建了objectmanagerfactory之后更新它们
编辑:堆栈跟踪如下: 下面是persistence.xml:
我有一些Spring托管类(通过xml配置),其中一个是SessionFactory,它被注入到另一个Spring托管类中。每当该类需要一个新的会话时,它就调用SessionFactory上的createSession。
我是Spring Boot的新手,我想用Spring Boot制作一个rest Web服务。我需要使用Jpa/Hibernate在数据库中保存一些数据。当我用@Entity注释我的域模型类,并将应用程序作为Spring boot应用程序启动时(顺便说一下,我的应用程序类有一个@EntityScan()注释)我得到以下错误: 在类路径资源 [组织/Spring框架/启动/自动配置/orm/jpa/H