如何映射具有错误管理的属性名称的旧数据库表

时间:2016-12-13 18:31:56

标签: spring-data spring-data-jpa

我正在为遗传数据库工作,我已经为其生成了以下实体类:

  

商家实体

@Entity
public class Business { ... }
  

Frontuser 实体

@Entity
public class Frontuser { ... }
  

审核实体

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

如图所示,列frontuser_idbusiness_id是其他表的外键列。列frontuserIdbusinessId是令人厌恶的(从命名约定的角度来看)。

值得注意的是,review表实际上包含四列frontuser_idbusiness_idfrontuserIdbusinessId

使用这些实体声明,我的应用程序无法启动以下异常:

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]

我不确定为什么会出现这个错误,因为我在实体类声明中明确命名了表列。

如何使用JPA映射这些属性?

0 个答案:

没有答案