0

I am creating a small desktop application in Intellij Idea 13, using Maven and OpeJPA. I run the application and this open ok, but when I search a cliente into the database with the application, the exception stack is launched.

This is the configuration in the persistence.xml

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

    <persistence-unit name="sacPU" transaction-type="RESOURCE_LOCAL">

        <class>cl.im.sac.Model.Cliente</class>
        <properties>
            <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
            <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/sac"/>
            <property name="openjpa.ConnectionUserName" value="sac-root" />
            <property name="openjpa.ConnectionPassword" value="sac.root.1844" />

            <property name="openjpa.jdbc.SynchronizeMappings"
                      value="buildSchema(SchemaAction='add,OpenJPATables=true',ForeignKeys=true)"/>
            <property name="openjpa.DynamicEnhancementAgent" value="true"/>
            <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=WARN, Tool=INFO, SQL=ERROR"/>
            <property name="openjpa.ConnectionFactoryProperties"
                      value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000"/>
            <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.MySQLDictionary"/>
            <property name="openjpa.DataCache" value="true"/>
            <property name="openjpa.QueryCache" value="true"/>
            <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
            <property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>
        </properties>
    </persistence-unit>
</persistence>

this is de Cliente class and ClienteDao class

@Table(name = "cliente", catalog = "sac")
@Entity
public class Cliente implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, unique = true)
    private Long id;
    private String nombre;
    private String apellidoPaterno;
    private String apellidoMaterno;
    private String sexo;
    private String run;
    private String direccion;
    private String comuna;
    private Date fechaIngreso;
    private int telefono;
    private int movil;
    private String email;
    private String usuario;
    private String pass;

    @OneToMany(cascade = CascadeType.ALL)
    private List<Producto> productos;

   /** METHODS **/

}

ClienteDao Class

public class ClienteDao {

    private static EntityManager entityManager = Persistencia.getEntityManager();

    public static Cliente find(Long id){
        return entityManager.find(Cliente.class,id);
    }

    public static Cliente findByRUN(String rn){
        Query q = entityManager.createQuery("select c from Cliente c where c.run=:run");
        q.setParameter("run",rn);
        if(!q.getResultList().isEmpty()){
            List c= q.getResultList();
            return (Cliente) c.get(0);
        }else{
            return null;
        }
    }
}

Persistence Class

public class Persistencia {

    private static EntityManager entityManager;

    static{
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("sacPU");
        entityManager = factory.createEntityManager();
    }

    public static EntityManager getEntityManager() {
        return entityManager;
    }
}

Exception stack

Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
    at cl.im.sac.Dao.ClienteDao.<clinit>(ClienteDao.java:17)
    at cl.im.sac.UI.Interfaz$1.actionPerformed(Interfaz.java:87)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6505)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6270)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:682)
    at java.awt.EventQueue$3.run(EventQueue.java:680)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:696)
    at java.awt.EventQueue$4.run(EventQueue.java:694)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: <openjpa-2.3.0-r422266:1540826 fatal general error> org.apache.openjpa.persistence.PersistenceException: null
    at org.apache.openjpa.enhance.ClassRedefiner.redefineClasses(ClassRedefiner.java:96)
    at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:176)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:312)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:236)
    at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:212)
    at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:155)
    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 cl.im.sac.Dao.Persistencia.<clinit>(Persistencia.java:16)
    ... 38 more
Caused by: java.lang.reflect.InvocationTargetException
    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.enhance.ClassRedefiner.redefineClasses(ClassRedefiner.java:85)
    ... 47 more
Caused by: java.lang.VerifyError
    at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
    at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
    ... 52 more

1 Answer 1

0
<property name="openjpa.RuntimeUnenhancedClasses" value="supported"/>

Please, don't use that property. Set it back to unsupported, or remove it all together. You need to either enhance at build time, or use the -javaagent.

OpenJPA Entity Enhancement

2
  • I set it back to unsupported, but the error change, Caused by: <openjpa-2.3.0-r422266:1540826 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: how use the -javaagent?
    – Isma90
    May 16, 2014 at 15:28
  • The link I posted documents how to enhance your Entities properly.
    – Rick
    May 16, 2014 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.