获得;java.lang.UnsupportedOperationException:“不支持”;

获得;java.lang.UnsupportedOperationException:“不支持”;,java,jakarta-ee,jpa,openjpa,ibm-rad,Java,Jakarta Ee,Jpa,Openjpa,Ibm Rad,我创建了一个小的JPA项目来保存学生记录。我使用Oracle数据库。我使用OpenJPA作为JPa提供者 我已经正确地创建了表student和相关序列 学生实体类 @Entity @Table(name = "Student") public class Student implements Serializable { private int id; private String name; private static final long serialVersio

我创建了一个小的JPA项目来保存学生记录。我使用Oracle数据库。我使用OpenJPA作为JPa提供者

我已经正确地创建了表student和相关序列

学生实体类

@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;
    }
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...");
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;
    }
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>
<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>
Util类

@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;
    }
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...");
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;
    }
数据成功保存在学生表中,但我有以下错误

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...
Java版本

JDK1.6

有人请告诉我这里有什么问题吗

更新:

我使用IBMRationalSoftwareArchitectforWebSphere软件进行此开发。这个问题与这个IDE有关。默认情况下,当我创建JPA项目时,它会添加IBMJRE。我刚刚删除了ibmjre并尝试了sunjre,然后就成功了。请告诉我为什么IBM jre不支持此功能?


首先,去掉这个属性。

这是我的增强器模板,它适用于OPENJPA: `



`

JPA规范要求对实体对象进行某种类型的监视,但规范没有定义如何实现这种监视。一些JPA提供程序在运行时自动生成新的子类或代理对象,这些子类或代理对象在用户的实体对象前面,而另一些提供程序使用字节码编织技术来增强实际的实体类对象。OpenJPA支持这两种机制,但强烈建议只使用字节码编织增强。不建议使用(由OpenJPA提供的)子类化支持(在OpenJPA2.0及更高版本中默认禁用)

这个问题的原因是我使用了对实体增强的子类化支持,但在OpenJPA2.0及更高版本中默认情况下是禁用的

我找到了解决这个问题的办法。我们必须在运行时通过在启动OpenJPA将要运行的JVM时提供javaagent来增强实体类

我将以下内容作为JVM参数

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

我从persistence.xml中删除了下面的行

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

工作持久性.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>
<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>

神谕
com.auditlog.model.BatchPrint

问题似乎已经解决了。请检查,我也尝试过这种情况,但没有运气。我犯了下面的错误。线程“main”org.apache.openjpa.persistence.ArgumentException中出现异常:尝试强制转换实例“com.jpa.demo.model”。Student@29e029e“要持久化失败。确保它已得到增强。FailedObject:com.jpa.demo.model。Student@29e029eEnhance您的实体使用构建时增强或通过-javaagenthanks-Rick。你能指导我做构建时增强吗?谢谢John。我如何使用我的项目?我应该在哪里添加这个?