0

I have problems with openjpa, with intellij idea 12 I generated file automatically "persitence.xml" and java objects, based on the models of the database, create a PaginaController.java and PaginaDao.java, but to create the generated EntityMaganerFactory.

PaginaDAO.java, this is where the application crashes.

package cl.im.ciclos.Dao;


import cl.im.ciclos.model.Pagina;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;


/**
 * Created with IntelliJ IDEA.
 * User: Ismael
 * Date: 15-09-13
 * Time: 05:17 PM
 * To change this template use File | Settings | File Templates.
 */
public class PaginaDao {

    static EntityManagerFactory factory;
    static EntityManager em;

    public PaginaDao(){

        factory = Persistence.createEntityManagerFactory("sistemaPU");
        em = factory.createEntityManager(); //==>this line generates the exception.
    }

    public void savePagina(String nombre, String file){
        em.getTransaction().begin();
        Pagina pagina = new Pagina();
        pagina.setNombre(nombre);
        pagina.setNombreArchivo(file);
        em.persist(pagina);
        em.getTransaction().commit();
    }
}

persitence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">

    <persistence-unit name="sistemaPU">

        <class>cl.im.ciclos.model.Pagina</class>

        <properties>
            <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/ciclos_calidad"/>
            <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
            <property name="openjpa.ConnectionUserName" value="sistema"/>
            <property name="openjpa.ConnectionPassword" value="sistema"/>

            <property name="openjpa.DynamicEnhancementAgent" value="true"/>
            <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
            <property name="openjpa.Log" value="SQL=TRACE"/>
            <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000"/>
        </properties>
    </persistence-unit>
</persistence>

project structure is as follows:

|---scr/main/java/cl.im.ciclos/
|         |                 |--/controller/PaginaController.java
|         |                 |--/Dao/PaginaDao.java
|         |                 |--/model/Pagina.java
|         |                 |--/web/bean/UserAgentTest.java
|         |                 |--/META-INF/persistence.xml
|         |--/webapp
|                |--...
|----pom.xml

well, change the META-INF folder to the location you indicated (/resources / META-INF), but only change the exception:

sep 23, 2013 4:37:25 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/main.xhtml]
javax.el.ELException: /main.xhtml: javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "sistemaPU" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:81)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:75)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:176)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "sistemaPU" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl
    at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
    at cl.im.ciclos.Dao.PaginaDao.<init>(PaginaDao.java:24)
    at cl.im.ciclos.controller.PaginaController.savePagina(PaginaController.java:22)
    at cl.im.ciclos.web.Bean.UserAgentTest.init(UserAgentTest.java:38)
    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.invoke(BeanELResolver.java:484)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:217)
    at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:141)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:78)
    ... 26 more
Caused by: <openjpa-2.2.0-r422266:1244990 fatal general error> org.apache.openjpa.persistence.PersistenceException: There was an error when invoking the static newInstance method on the named factory class "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory".  See the nested exception for details.
    at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:73)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:147)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:153)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:62)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
    ... 41 more
Caused by: org.apache.openjpa.lib.util.ParseException: Equivalent property keys "openjpa.ConnectionUserName" and "javax.persistence.jdbc.user" are specified in configuration.
    at org.apache.openjpa.lib.conf.Value.setLoadKey(Value.java:153)
    at org.apache.openjpa.lib.conf.ConfigurationImpl.findValue(ConfigurationImpl.java:771)
    at org.apache.openjpa.lib.conf.ConfigurationImpl.fromProperties(ConfigurationImpl.java:649)
    at org.apache.openjpa.lib.conf.MapConfigurationProvider.setInto(MapConfigurationProvider.java:85)
    at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationProviderImpl.setInto(PersistenceProductDerivation.java:695)
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newInstance(JDBCBrokerFactory.java:60)
    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 org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:131)
    at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:65)
    ... 46 more

sep 23, 2013 4:37:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/sistema.ciclos.calidad] threw exception [Explicit persistence provider error(s) occurred for "sistemaPU" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl] with root cause
org.apache.openjpa.lib.util.ParseException: Equivalent property keys "openjpa.ConnectionUserName" and "javax.persistence.jdbc.user" are specified in configuration.
    at org.apache.openjpa.lib.conf.Value.setLoadKey(Value.java:153)
    at org.apache.openjpa.lib.conf.ConfigurationImpl.findValue(ConfigurationImpl.java:771)
    at org.apache.openjpa.lib.conf.ConfigurationImpl.fromProperties(ConfigurationImpl.java:649)
    at org.apache.openjpa.lib.conf.MapConfigurationProvider.setInto(MapConfigurationProvider.java:85)
    at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationProviderImpl.setInto(PersistenceProductDerivation.java:695)
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newInstance(JDBCBrokerFactory.java:60)
    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 org.apache.openjpa.kernel.Bootstrap.invokeFactory(Bootstrap.java:131)
    at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:65)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:147)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:91)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:153)
    at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:62)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
    at cl.im.ciclos.Dao.PaginaDao.<init>(PaginaDao.java:24)
    at cl.im.ciclos.controller.PaginaController.savePagina(PaginaController.java:22)
    at cl.im.ciclos.web.Bean.UserAgentTest.init(UserAgentTest.java:38)
    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.invoke(BeanELResolver.java:484)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:217)
    at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:141)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:78)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:75)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:176)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

And the line where it falls change:

public PaginaDao(){

            factory = Persistence.createEntityManagerFactory("sistemaPU");//==>this line generates the new exception.
            em = factory.createEntityManager(); 
        }
4

1 回答 1

0

看起来您persistence.xml没有被 OpenJPA 接收,因为 META-INF 文件夹应该位于不同的位置。它应该看起来像这样(persistence.xmlsrc/main/resources/META-INF):

|---scr/main/java/cl.im.ciclos/
|         |                 |--/controller/PaginaController.java
|         |                 |--/Dao/PaginaDao.java
|         |                 |--/model/Pagina.java
|         |                 |--/web/bean/UserAgentTest.java
|         |                 
|         |--/webapp
|         |      |--...
|         |--/resources/META-INF/persistence.xml
|
|----pom.xml
于 2013-09-23T19:15:16.553 回答