hibernate ManyToOne 与 OfertaInscripcio 映射 Oferta 时的标识符无效

发布于 2025-01-10 16:03:56 字数 2020 浏览 0 评论 0原文

环境:

  • Jboss 7.2
  • Java 11
  • Hibernate

用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
...

Oferta

@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;
...

Environment:

  • Jboss 7.2
  • Java 11
  • Hibernate

It must be some kind of error when mapping database fields with java properties, it is adding the prefix OFERTA_ to OFT_ID(primary key), but I can not see where is this happening.

Oferta 1->N OfertaInscripcio

ERROR ORA-00904: "OFERTA_OFT_ID": invalid identifier

It should be only OFT_ID

Any idea?

Log error

...
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
...

Oferta

@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;
...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2025-01-17 16:03:56

您必须将 @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;
}

You have to put @Joincolumn on the field oferta specifying the column name. If you don't have it, the name is retrieved by the variable name.

@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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文