Mysql 错误:无法与<;一起使用标识列键生成;联合子类>;(每类表)

Mysql 错误:无法与<;一起使用标识列键生成;联合子类>;(每类表),mysql,spring,hibernate,hibernate-mapping,class-table-inheritance,Mysql,Spring,Hibernate,Hibernate Mapping,Class Table Inheritance,我使用Hibernate保存实体,其中所有实体都继承自一个基本抽象实体。对于所有具体实体,都分别有数据库表,带有autoincrement主键列。但使用GenerationType作为“AUTO”或“IDENTITY”会产生错误。我希望数据库表中代表每个具体实体类的所有记录都应该具有顺序递增的ID值 com.something.SuperClass: @Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public a

我使用Hibernate保存实体,其中所有实体都继承自一个基本抽象实体。对于所有具体实体,都分别有数据库表,带有autoincrement主键列。但使用GenerationType作为“AUTO”或“IDENTITY”会产生错误。我希望数据库表中代表每个具体实体类的所有记录都应该具有顺序递增的ID值

com.something.SuperClass:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
    private static final long serialVersionUID = -695503064509648117L;

    long confirmationCode;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!!
    public long getConfirmationCode() {
        return confirmationCode;
    }

    public void setConfirmationCode(long confirmationCode) {
        this.confirmationCode = confirmationCode;
    }
}
@Entity
public abstract class Subclass extends SuperClass {
    private static final long serialVersionUID = 8623159397061057722L;

    String name;

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Caused by: org.hibernate.MappingException: Cannot use identity column key
generation with <union-subclass> mapping for: com.something.SuperClass
What's the best and most convenient way for me to generate the ID's? I do not want to change my inheritance strategy.
com.something.SubClass:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
    private static final long serialVersionUID = -695503064509648117L;

    long confirmationCode;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!!
    public long getConfirmationCode() {
        return confirmationCode;
    }

    public void setConfirmationCode(long confirmationCode) {
        this.confirmationCode = confirmationCode;
    }
}
@Entity
public abstract class Subclass extends SuperClass {
    private static final long serialVersionUID = 8623159397061057722L;

    String name;

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Caused by: org.hibernate.MappingException: Cannot use identity column key
generation with <union-subclass> mapping for: com.something.SuperClass
What's the best and most convenient way for me to generate the ID's? I do not want to change my inheritance strategy.
给了我这个例外:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class SuperClass implements Serializable {
    private static final long serialVersionUID = -695503064509648117L;

    long confirmationCode;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO) // Causes exception!!!
    public long getConfirmationCode() {
        return confirmationCode;
    }

    public void setConfirmationCode(long confirmationCode) {
        this.confirmationCode = confirmationCode;
    }
}
@Entity
public abstract class Subclass extends SuperClass {
    private static final long serialVersionUID = 8623159397061057722L;

    String name;

    @Column(nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Caused by: org.hibernate.MappingException: Cannot use identity column key
generation with <union-subclass> mapping for: com.something.SuperClass
What's the best and most convenient way for me to generate the ID's? I do not want to change my inheritance strategy.
原因:org.hibernate.MappingException:无法使用标识列键
使用映射生成:com.something.SuperClass
对我来说,生成ID的最佳和最方便的方法是什么?我不想改变我的继承策略。
我知道如果我将GenerationType从“AUTO”更改为“TABLE”,它是可以解决的,但是这个解决方案的问题是,生成的键不是按照精确的顺序排列的。它在键之间留下了很大的间隙

我正在寻找一种解决方案,它允许所有表使用Mysql自动增量主列生成的自动增量值

提前感谢大家

注:我已经看过以下帖子:

我也有同样的问题,可能是重复的。你找到什么线索了吗?