java java-ee jpa openjpa ibm-rad

Obteniendo "java.lang.UnsupportedOperationException:"



java-ee jpa (3)

Creé el pequeño proyecto JPA para conservar un registro de Estudiante. Yo uso la base de datos Oracle. Uso OpenJPA como el proveedor de JPa.

He creado correctamente el alumno de tabla y las secuencias relevantes.

Clase de entidad estudiantil

@Entity @Table(name = "Student") public class Student implements Serializable { private int id; private String name; private static final long serialVersionUID = 1L; public Student() { super(); } @Id @Column(name = "ID") @SequenceGenerator(name = "TRAIN_SEQ", sequenceName = "STUDENT_SEQ") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TRAIN_SEQ") public int getId() { return this.id; } public void setId(int id) { this.id = id; } @Column(name = "NAME") public String getName() { return this.name; } public void setName(String name) { this.name = name; }

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="JPAOracleDemo"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <class>com.jpa.demo.model.Student</class> <properties> <property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@TEST:50111:TESTPEGAD1" /> <property name="openjpa.ConnectionDriverName" value="oracle.jdbc.driver.OracleDriver" /> <property name="openjpa.ConnectionUserName" value="admin" /> <property name="openjpa.ConnectionPassword" value="admin" /> <property name="openjpa.RuntimeUnenhancedClasses" value="supported" /> <property name="openjpa.jdbc.Schema" value="MYSCHEMA" /> </properties> </persistence-unit> </persistence>

Clase de cliente

OpenJPAEntityManager em = JPAUtil.getEntityManager(); OpenJPAEntityTransaction tx = em.getTransaction(); tx.begin(); // Create the instance of Employee Entity class Student student = new Student(); student.setName("A.Ramesh"); // JPA API to store the Student instance on the database. em.persist(student); tx.commit(); em.close(); System.out.println("Done...");

Clase Util

private static OpenJPAEntityManagerFactory emf = OpenJPAPersistence .createEntityManagerFactory("JPAOracleDemo", "META-INF/persistence.xml"); private static OpenJPAEntityManager entManager; /** * No need to create any instance for this Util. */ private JPAUtil() { } /** * Get {@link EntityManager}. * * @return the {@link EntityManager} */ public static OpenJPAEntityManager getEntityManager() { if (entManager == null || !entManager.isOpen()) { entManager = emf.createEntityManager(); } return entManager; }

Los datos persisten en la tabla de estudiantes con éxito, pero tengo el siguiente error

Exception in thread "Attachment 60230" java.lang.UnsupportedOperationException: cannot get the capability, performing dispose of the retransforming environment at com.ibm.tools.attach.javaSE.Attachment.loadAgentLibraryImpl(Native Method) at com.ibm.tools.attach.javaSE.Attachment.loadAgentLibrary(Attachment.java:253) at com.ibm.tools.attach.javaSE.Attachment.parseLoadAgent(Attachment.java:235) at com.ibm.tools.attach.javaSE.Attachment.doCommand(Attachment.java:154) at com.ibm.tools.attach.javaSE.Attachment.run(Attachment.java:116) Exception in thread "main" java.lang.UnsupportedOperationException: cannot get the capability, performing dispose of the retransforming environment at sun.instrument.InstrumentationImpl.isRetransformClassesSupported0(Native Method) at sun.instrument.InstrumentationImpl.isRetransformClassesSupported(InstrumentationImpl.java:124) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:600) at org.apache.openjpa.enhance.ClassRedefiner.canRedefineClasses(ClassRedefiner.java:123) at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:122) at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:304) at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:228) at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:202) at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156) at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:213) at com.ibm.ws.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:45) at com.ibm.ws.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:30) at com.jpa.demo.util.JPAUtil.getEntityManager(JPAUtil.java:32) at com.jpa.demo.client.JPAClient.main(JPAClient.java:13) 1045 JPAOracleDemo INFO [main] openjpa.Enhance - Creating subclass for "[class com.jpa.demo.model.Student]". This means that your application will be less efficient and will consume more memory than it would if you ran the OpenJPA enhancer. Additionally, lazy loading will not be available for one-to-one and many-to-one persistent attributes in types using field access; they will be loaded eagerly instead. Done...

Versión de Java

JDK 1.6

¿Alguien por favor hágamelo saber cuál es el problema aquí?

Actualizado:

Utilicé IBM Rational Software Architect para Websphere Software para este desarrollo. este problema es con este IDE. Cuando creo el proyecto JPA de manera predeterminada, agrega el IBM jre. Acabo de eliminar la IBM jre y probé con SUN jre, pero fue un éxito. Indíqueme por qué esta función no es compatible con IBM jre?


Esta es mi plantilla enhancer, esto funciona correctamente para OPENJPA: `

<path id="enhance.cp"> <pathelement location="${basedir}${file.separator}${build.dir}" /> <fileset dir="${basedir}${file.separator}ext_libs/"> <include name="**/*.jar" /> </fileset> </path> <property name="cp" refid="enhance.cp" /> <target name="openjpa.libs.check" unless="openjpa.libs"> <fail message="Please set -Dopenjpa.libs in your builder configuration!" /> </target> <target name="build.dir.check" unless="build.dir"> <fail message="Please set -Dbuild.dir in your builder configuration!" /> </target> <target name="enhance" depends="openjpa.libs.check, build.dir.check"> <echo message="${cp}" /> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask"> <classpath refid="enhance.cp" /> </taskdef> <openjpac> <classpath refid="enhance.cp" /> <configpropertiesFile="${basedir}${file.separator}src${file.separator}main${file.separator} resources${file.separator}META-INF${file.separator}persistence.xml" /> </openjpac> </target>

`


La especificación JPA requiere algún tipo de supervisión de los objetos de la Entidad, pero la especificación no define cómo implementar esta supervisión. Algunos proveedores de JPA generan automáticamente nuevas subclases u objetos proxy que hacen frente a los objetos de la Entidad del usuario en el tiempo de ejecución, mientras que otros usan tecnologías de tejer códigos de bytes para mejorar los objetos de la clase de Entidad real. OpenJPA es compatible con ambos mecanismos, pero sugiere únicamente el uso de la mejora del tejido de código byte. No se recomienda el soporte de subclases (proporcionado por OpenJPA) (y está deshabilitado por defecto en OpenJPA 2.0 y más adelante). (Fuente: http://openjpa.apache.org/entity-enhancement.html )

La causa de este problema es que utilicé el soporte de subclases para la mejora de la entidad, pero está deshabilitado por defecto en OpenJPA2.0 y más allá.

Encontré la solución para este problema. Tenemos que mejorar la clase de entidad en tiempo de ejecución proporcionando un javaagent al iniciar la JVM en la que se ejecuta OpenJPA.

Puse algo así como el siguiente como argumento de JVM

-javaagent: C: /OpenJPA/apache-openjpa-2.0.0/openjpa-2.0.0.jar

Y eliminé la línea de abajo de persistence.xml

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

Trabajo persistence.xml

<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="DataSourceDemo"> <jta-data-source>oracleDS</jta-data-source> <class>com.auditlog.model.BatchPrint</class> <properties> <property name="openjpa.ConnectionUserName" value="admin" /> <property name="openjpa.ConnectionPassword" value="test" /> <property name="openjpa.jdbc.Schema" value="defaultScheme" /> </properties> </persistence-unit> </persistence>


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

Para empezar, deshazte de esa propiedad.