Jason
Jason

Reputation: 123

Why is an Entity not persisted into database under TomEE 1.7 and EclipseLink 2.4.2?

As i have already worked JPA 2.1 with eclipselink 2.5.1 everything fine in that configuration. but due to some requirements i have came to JPA 2.0 with eclipselink 2.4.2 and now i am struggling to persist entities into database. as i am running my application while registering a user the data is getting stored some where and it is retrieved fine. but it is not getting persisted into database (MySql). Even i cant figure out the actual usage of JTA and RESOURCE LOCAL could someone help me here is my code

Create.java (register method)

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>

error log:

<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)

even i restart the eclipse IDE the values are still there. I am so confused. Is there any configuration issue existing here?

Upvotes: 1

Views: 859

Answers (3)

Jason
Jason

Reputation: 123

I got it i wanted others to know the exact problem. As i am using TomEE which is JavaEE server it is having openJPA as a default persistence provider.

  1. If you want to use Other persistence providers we need to specify the <provider>your provider</provider> explicitly in persistence .xml

  2. TomEE uses JTA as a default Transaction Manager. If you want to use RESOURCE_LOCAL you need to specify the transaction-type="RESOURCE_LOCAL" and also you need to specify the <non-jta-data-source>to be used by the application. otherwise the server will use JTA even though you specified the transaction type as RESOURCE_LOCAL

  3. In order to configure JNDI Datasource refer this link.

Now the values are getting stored into the local database... remember you need to have all the libraries into your lib folder, also the jdbc connector into the server's lib folder so that that it would go well with the JNDI Datasource.

Upvotes: 1

mgsCatDev
mgsCatDev

Reputation: 136

Are you sure you are using eclipselink libraries? Maybe your server has it's own openjpa libraries and you have not override them. If you look for similar problems on the net (like this, or this), people that have those problems are using openjpa.

Upvotes: 0

Giovanny Velez
Giovanny Velez

Reputation: 106

Have you tried to flush the em after persist?

Upvotes: 0

Related Questions