休眠 ManyToOne 映射 Oferta 与 OfertaInscripcio 的标识符无效

Invalid identifier on hibernate ManyToOne mapping Oferta with OfertaInscripcio

环境:

使用 java 属性映射数据库字段时一定是某种错误,它将前缀 OFERTA_ 添加到 OFT_ID(主键),但我看不出这是在哪里发生的.

Oferta 1->N OfertaInscripcio

错误 ORA-00904:“OFERTA_OFT_ID”:标识符无效

应该只有OFT_ID

有什么想法吗?

日志错误

...
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
...
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "OFERTA_OFT_ID": invalid identifier
...
Caused by: Error : 904, Position : 275, Sql = insert into AF_OFE_OFERTA_INSCRIPCIO (CREATEDAT, UPDATEDAT, oferta_OFT_ID,...ID) values (:1 , ... , :29 ), OriginalSql = insert into AF_OFE_OFERTA_INSCRIPCIO (CREATEDAT, UPDATEDAT, ...oferta_OFT_ID, ..., ID) values (?, ?, ?, ?, ?, ?, ?, ?), Error Msg = ORA-00904: "OFERTA_OFT_ID": invalid identifier
...

奥费塔

@Entity
@Table(name = "AF_OFE_OFERTA")
public class Oferta implements Serializable {
...

@Id
@Column(name = "OFT_ID")
@SequenceGenerator(name = "AF_OFERTA_GENERATOR", sequenceName = "AF_OFERTA_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AF_OFERTA_GENERATOR")
private Long id;

@OneToMany(mappedBy = "oferta", cascade = CascadeType.ALL, orphanRemoval = true)
private List<OfertaInscripcio> inscripcions = new ArrayList<>();
...

OfertaInscipcio

@Entity
@Table(name = "AF_OFE_OFERTA_INSCRIPCIO")
public class OfertaInscripcio implements Serializable {

...
    @Id
    @Column(name = "ID")
    @SequenceGenerator(name = "AF_OFERTAI_GENERATOR", sequenceName = "AF_OFERTAI_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AF_OFERTAI_GENERATOR")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    private Oferta oferta;

    @Column(name = "OFERTAID", insertable = false, updatable = false)
    private Long idOferta;
...

您必须将 @Joincolumn 放在字段 oferta 上以指定列名。如果您没有,则通过变量名检索名称。

@Entity
@Table(name = "AF_OFE_OFERTA_INSCRIPCIO")
public class OfertaInscripcio implements Serializable {

    @Id
    @Column(name = "ID")
    @SequenceGenerator(name = "AF_OFERTAI_GENERATOR", sequenceName = "AF_OFERTAI_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AF_OFERTAI_GENERATOR")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "OFERTAID", referencedColumnName = "OFT_ID")
    private Oferta oferta;

    @Column(name = "OFERTAID", insertable = false, updatable = false)
    private Long idOferta;
}