【问题标题】:Datanucleus 5.2.x 6.0.0-m1 JDO Enum usage, generated code not compilingDatanucleus 5.2.x 6.0.0-m1 JDO Enum 使用,生成的代码未编译
【发布时间】:2021-06-05 11:02:32
【问题描述】:

我正在尝试将 ISIS 与 JDO 结合使用。我偶然发现了一个 Enums 问题,我可以在直接/简单的 java JDO 项目中重现该问题。

代码可以从

curl https://codeload.github.com/apache/isis-app-helloworld/zip/jdo | jar xv

我在 pom.xml 中添加了 lombok 依赖项:

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
        </dependency>

我创建了一个类

package domainapp.modules.hello.dom.hwo;

import javax.jdo.annotations.IdentityType;

import lombok.AllArgsConstructor;
import lombok.Getter;

@javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE, schema = "hello" )
@AllArgsConstructor
@Getter
public enum HelloWorldTypeEnum {
    BIG,
    SMALL;
}

并在 HelloWorldObject 中添加以下成员:

    @Getter @Setter
    @Extension(vendorName="datanucleus", key="enum-check-constraint", value="true")
    private HelloWorldTypeEnum type = HelloWorldTypeEnum.BIG;

生成的 QHelloWorldObject 没有编译:

...
    public QHelloWorldObject(PersistableExpression parent, String name, int depth)
    {
        super(parent, name);
        if (depth > 0)
        {
            this.type = new EnumExpressionImpl(this, "type", depth-1);
        }
        else
        {
            this.type = null;
        }
        this.name = new StringExpressionImpl(this, "name");
        this.notes = new StringExpressionImpl(this, "notes");
    }
...

线

            this.type = new EnumExpressionImpl(this, "type", depth-1);

有错误:

- The constructor EnumExpressionImpl(QHelloWorldObject, String, int) is undefined
- EnumExpressionImpl is a raw type. References to generic type EnumExpressionImpl<T> should be parameterized

我创建了干净的项目,剥离了所有 ISIS 的东西,并将其减少到只有 2 个 java 文件,并使用 OpenJDK 11 使用 Datanucleus 5.2.8 和 6.0.0-m1 进行了测试。结果总是一样的。

我在使用 OpenJDK 11 的 Opensuse 15.2 机器上。

根据https://www.datanucleus.org/products/accessplatform/jdo/mapping.html 支持枚举。

有人知道出了什么问题吗?

【问题讨论】:

  • 我也使用 java 1.8 和 Datanucleus 5.2.8(maven 存储库中的某些东西是 5.2.9 或 5.2.7)完成了此操作,结果相同。

标签: java enums jdo datanucleus


【解决方案1】:

结果就这么简单:不要让枚举持久化。

删除线:

@javax.jdo.annotations.PersistenceCapable(identityType = IdentityType.DATASTORE, schema = "hello" )

来自枚举定义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 2015-07-05
    • 2017-06-29
    • 1970-01-01
    • 2015-12-13
    • 1970-01-01
    相关资源
    最近更新 更多