0

我最近从 hibernate-core 4.1.7 升级到 5.0.9 并且对这段代码有问题:

    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name = "FK_AAA", foreignKey = @ForeignKey(name = "CS_BBB"))
    @org.hibernate.annotations.Index(name = "IDX_CCC", columnNames = "FK_DDD")
    private ImportData importData;

这会生成指向定义类的正确外部列,但也会在同一类上生成一列: IMPORTDATA RAW(255)

为什么会生成这个 raw(255) 列?我认为它不是用 Hibernate-core 4.1.7 生成的

任何的想法 ?

更新 1:这里是更长的代码片段:


@MappedSuperclass
@Access(AccessType.PROPERTY)
public abstract class BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public abstract Long getId();
}


@Entity
@Table(name = "IMPORT_DATA", uniqueConstraints = {
        @UniqueConstraint(name = "UC_IMP_BID", columnNames = {"BUSINESS_ID"})
}, indexes = {
        @Index(name = "IDX_IMP_DGXML_ID", columnList = "FK_DGXML_ID"),
        @Index(name = "IDX_IMP_IMPXML_ID", columnList = "FK_IMPXML_ID")
})
public class ImportData extends BaseEntity { 

  @Id @GeneratedValue(strategy = GenerationType.AUTO) 
  public Long getId() { return id; } 
  // ... 

}



@Entity(name = "MUTATION")
@Table(name = "MUTATION")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
@SequenceGenerator(name = "mutationsSeq", sequenceName = "MUTATIONS_SEQUENCE", allocationSize = 1)
public abstract class Mutation extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "mutationsSeq")
    private Long id;

  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    @JoinColumn(name = "FK_IMP_ID", foreignKey = @ForeignKey(name = "CS_MUT_IMP_ID"))
    @org.hibernate.annotations.Index(name = "IDX_MUT_IMP_ID", columnNames = "FK_IMP_ID")
    protected ImportData importData;

}


@Entity(name="XXX")
@DiscriminatorValue("XXX_DISC")
public class XXX extends Mutation {
   // ...
}
4

1 回答 1

0

我找到了一个关于使用 Hibernate 映射复合键在 Oracle 中生成原始字段的答案:

我在字段和方法上混合注释。我在抽象超类上也有@Id,在派生类上也有重新定义。

修复这两个元素,清理 DB 并在“创建”ddl 模式下重新生成证明修复不再生成 RAW 字段类型。

感谢您的所有帮助!

于 2021-04-06T14:51:10.313 回答