hibernate ManyToOne 与 OfertaInscripcio 映射 Oferta 时的标识符无效
环境:
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将
@Joincolumn
放在指定列名称的oferta
字段上。如果没有,则通过变量名称检索名称。You have to put
@Joincolumn
on the fieldoferta
specifying the column name. If you don't have it, the name is retrieved by the variable name.