Java @鉴别器值类型不匹配:无法从整数转换为字符串

Java @鉴别器值类型不匹配:无法从整数转换为字符串,java,eclipse,jpa,Java,Eclipse,Jpa,虽然我将父类定义为使用Integer类型的鉴别器列,但编译器始终给出错误:类型不匹配:无法使用Integer鉴别器值将子类从Integer转换为String @Table(name="ITEMS") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name="ITEM_CATEGORY",discriminatorType=DiscriminatorType.

虽然我将父类定义为使用Integer类型的鉴别器列,但编译器始终给出错误:
类型不匹配:无法使用Integer鉴别器值将子类从Integer转换为String

@Table(name="ITEMS")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="ITEM_CATEGORY",discriminatorType=DiscriminatorType.INTEGER)
public class Item { ....}


@Entity
@DiscriminatorValue(value=ItemCategory.Values.LEARNING_DUTY)
public class LearningDuty extends Item {...}


public static class Values {
        
        public static final Integer LEARNING_DUTY = 3;

    }
pom文件:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <spring.version>5.0.2.RELEASE</spring.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>

org.springframework.boot

Java是一种静态类型语言。因此
discriminatorType=discriminatorType.INTEGER
无法更改
DiscriminatorValue
值的类型

:

DiscriminatorValue
注释指定鉴别器值 每节课。尽管此注释的值始终是字符串,但 实现将根据
鉴别器列
解析它
discriminatorType
以上属性

因此,必须按如下方式指定鉴别器值:

@DiscriminatorValue(value=""+ItemCategory.Values.LEARNING_DUTY)

这是否回答了你的问题:@不幸的是,塔什基西没有