为什么实体不会在TomEE 1.7和EclipseLink 2.4.2下持久存储到数据库中?

时间:2015-07-25 09:49:29

标签: jpa eclipselink jpa-2.0 tomee

因为我已经使用eclipselink 2.5.1工作了JPA 2.1,所以该配置中的一切都很好。但由于一些要求,我已经使用eclipselink 2.4.2来到JPA 2.0,现在我正在努力将实体持久化到数据库中。因为我在注册用户时运行我的应用程序,数据被存储在一些地方并且检索得很好。但它没有持久存入数据库(MySql)。即使我无法弄清楚 JTA RESOURCE LOCAL 的实际使用情况,有人可以帮助我这里是我的代码

Create.java(注册方法)

public static int register(String first, String last, String email,
            String date, String phone, String address, String pin, Login login) {
        try {
            System.out.println("registering persisting the entity");
            EntityManagerFactory emf = Persistence
                    .createEntityManagerFactory("FirstEE");

            EntityManager manager = emf.createEntityManager();

            manager.getTransaction().begin();
            //
            // Query query = manager
            // .createQuery("select l from Truck l");

            Login log = login;

            System.out.println(log.getUsername() + "username"
                    + log.getPassword() + "password");

            User reg = new User();
            reg.setLogin(log);
            reg.setDate(date);
            reg.setEmail(email);
            reg.setFirst(first);
            reg.setLast(last);
            reg.setPhone(phone);
            reg.setAddress(address);
            reg.setPin(pin);
            manager.flush();
            manager.persist(reg);

            manager.getTransaction().commit();

            manager.close();
            emf.close();
            // FacesContext.getCurrentInstance().addMessage("reg:result",
            // new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message",
            // "Registered Successfully"));
            FacesContext facesContext = FacesContext.getCurrentInstance();
            FacesMessage facesMessage = new FacesMessage(
                    "Registered Successfully");
            facesContext.addMessage(null, facesMessage);
            System.out.println("after message global");
            return 1;
        } catch (Exception e) {
            System.out.println("hai this is exception caught:" + e);
            System.out.println("hai" + e.getMessage());
            FacesContext.getCurrentInstance().addMessage(
                    "reg:result",
                    new FacesMessage("Something went wrong",
                            "\tSomething went wrong\t"));
            // FacesContext facesContext = FacesContext.getCurrentInstance();
            // FacesMessage facesMessage = new
            // FacesMessage("Something went wrong");
            // facesContext.addMessage(null, facesMessage);

        }
        return 0;

    }

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<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="FirstEE" transaction-type="RESOURCE_LOCAL">
<!--        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> -->
<!--         <non-jta-data-source>FirstEE</non-jta-data-source> -->
<!--        <exclude-unlisted-classes>false</exclude-unlisted-classes> -->
        <class>com.jason.Entity.User</class>
        <class>com.jason.ManagedBean.Login</class>

        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/yash" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="eclipselink.logging.level" value="FINEST" />
            <property name="eclipselink.ddl-generation" value="create-tables" />
        </properties>


    </persistence-unit>
</persistence>

错误日志:

<openjpa-2.4.0-r422266:1674604 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
com.jason.Entity.User
com.jason.ManagedBean.Login".
    at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:115)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:311)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:235)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:211)
    at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
    at com.jason.service.GetUser.get(GetUser.java:45)
    at com.jason.ManagedBean.Register.getAllUser(Register.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:183)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:161)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
    at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:46)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at org.apache.webbeans.el22.WrappedValueExpression.getValue(WrappedValueExpression.java:70)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:462)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    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 javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at org.apache.myfaces.tomahawk.application.ResourceViewHandlerWrapper.renderView(ResourceViewHandlerWrapper.java:169)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    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 com.jason.Filter.Adminfilter.doFilter(Adminfilter.java:62)
    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.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
    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:318)
    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)

即使我重新启动eclipse IDE,值仍然存在。我感到很困惑。这里是否存在任何配置问题?

3 个答案:

答案 0 :(得分:1)

我明白我希望别人知道确切的问题。因为我使用的是TomEE,它是JavaEE服务器,所以它将openJPA作为默认的持久性提供程序。

  1. 如果您想使用其他持久性提供程序,我们需要在持久性.xml

  2. 中明确指定<provider>your provider</provider>
  3. TomEE使用 JTA 作为默认的事务管理器。如果要使用 RESOURCE_LOCAL ,则需要指定transaction-type="RESOURCE_LOCAL",还需要指定应用程序使用的<non-jta-data-source>。即使您将交易类型指定为 RESOURCE_LOCAL

  4. ,服务器也将使用JTA
  5. 要配置JNDI数据源,请参阅此link

  6. 现在这些值已存储到本地数据库中......请记住,您需要将所有库都放入lib文件夹,同时将jdbc连接器放入服务器的lib文件夹中,以便它可以很好地与JNDI数据源配合使用。

答案 1 :(得分:0)

你有没有试过在持续存在后冲洗它?

答案 2 :(得分:0)

您确定使用的是eclipselink库吗?也许你的服务器有自己的openjpa库,你没有覆盖它们。 如果您在网上查找类似的问题(例如thisthis),那些遇到这些问题的人就会使用openjpa。