Issue
I recently upgraded from hibernate-core 4.1.7 to 5.0.9 and Have problem with this code:
@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;
This generate correct foreign columns pointing to the defining class, but also generating a column on the same class:
IMPORTDATA RAW(255)
Why is this raw(255) column generated ? I think it was not generated with Hibernate-core 4.1.7
any idea ?
Update 1: here is longer code fragments:
@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 {
// ...
}
Solution
I found an answer on Mapping composite key with Hibernate produces a raw field in Oracle:
I was mixing annotations on fields and methods. I also had @Id on an abstract superclass, and a redefinition on a derived class.
Fixing theses two elements, cleaning DB and regenerating in "create" ddl mode proved that the fix was no longer generating RAW field type.
Thanks for all your helps!
Answered By - Cédric Dutoit