java - OpenJPA 增强 - 不支持 {0} Embeddable 中定义的身份字段

标签 java mysql jpa openjpa

我将以下 JPA 代码与 MySQL DB 和 OpenJPA 2.2.2 结合使用:

@MappedSuperclass
public abstract class IdentifiableEntity implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    // getters, setters, etc.
}

@Entity
public class User extends IdentifiableEntity {
    private String name;

    // getters, setters, etc.
}

在 JSE 环境中执行 User user = new User(); 时收到此消息:

ERROR [main] openjpa.Enhance - The identity field defined in the IdentifiableEntity Embeddable is not supported.

我尝试在 Oracle 1.6 JDK 上使用 OpenJPA 动态加载类增强器运行。尽管有该消息,代码似乎仍在正确执行。

为什么我会收到此消息?是良性的吗?

以下是persistence.xml的内容:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 <persistence-unit name="persistenceUnit">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <properties>
      <property name="openjpa.ConnectionURL"
        value="jdbc:mysql://localhost:3306/playground?useUnicode=true&amp;characterEncoding=UTF-8"/>
      <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
      <property name="openjpa.ConnectionUserName" value="guest"/>
      <property name="openjpa.ConnectionPassword" value="guest"/>

      <!-- Classes should be enhanced at build-time for production. -->
      <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
      <property name="openjpa.DynamicEnhancementAgent" value="true"/>

      <!-- Enable logging -->
      <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />
      <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
    </properties>
 </persistence-unit>
</persistence>

最佳答案

同样的错误。经过一番调试后,我发现打印出来的行来自以下补丁: OPENJPA-2233 。它还会更改添加 pcNewObjectIdInstance 的条件,但不会影响 MappedSuperclass 对象。

我认为我们不应该打扰。我将在 apache JIRA 上创建一个问题。

关于java - OpenJPA 增强 - 不支持 {0} Embeddable 中定义的身份字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16619860/

相关文章:

mysql - 如何保护用户名、密码、api_keys

java - 在子实体中更新或插入新行

jpa - 使用 SingleConnection=true 更新浮点值不会为 UCanAccess 保留

java - 修复 Array out of bounds Exception New Array Exception

java - Google protobuf可以用于android中C和Java服务之间的通信吗?

java - 面向方面编程中的四人组模式用法?

java - 将货币转换为 Double 时 String 类错误

mysql - 使用不同表中多行的信息更新一个表行

php - 如何使用 MySQLi 向 MySQL 中插入数据?

java - Spring中的JPA悲观锁和JpaTemplate