I'm working on a legacy database for which I have generated the following entity classes:
Business entity
@Entity
public class Business { ... }
Frontuser entity
@Entity
public class Frontuser { ... }
Review entity
@Entity
@Table(name="review")
public class Review {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private int id;
@Column(nullable=false)
private int businesshoteltravelId;
@Column(name = "frontuser_id", nullable=false)
private int frontuser_id;
@Column(name = "business_id", nullable=false)
private int business_id;
@ManyToOne
@JoinColumn(name="frontuserId", nullable=false)
private Frontuser frontuser;
@ManyToOne
@JoinColumn(name="businessId", nullable=false)
private Business business;
}
As seen, the columns frontuser_id
and business_id
are foreign key columns to other tables. Columns frontuserId
and businessId
are an abomination (from a naming convention perspective).
It is worth noting that the review
table actually contains the four columns frontuser_id
, business_id
, frontuserId
and businessId
.
With these entity declarations, my application fails to start with the following exception:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory'
Table [review] contains physical column name [business_id] referred to by multiple physical column names: [businessId], [business_id]
I am not sure why this error occurs, given that I have explicitly named table columns in the entity class declaration.
How I can map these attributes with JPA?