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;
...
CodePudding user response:
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;
}