今天修改实体类时项目启动报错:
org.hibernate.MappingException: Unable to find column with logical name: product_type_id in org.hibernate.mapping.Table(product_type_view) and its related supertables and secondary tables
-------------------------------------------------------------------------------------------------------------------------------------
添加一对多后启动报错,添加@Column后,正常启动
@Getter @Setter @Entity @Table(name = "product_type_view") public class ProductTypeView { /** 产品类型id {@link ProductType#id} */ @Id @Column(name = "product_type_id") private Long productTypeId; /** 产品类型名 */ private String productTypeName; /** * 父级产品id {@link ProductType#parentId}<br> * </>(若为顶级产品类型,则此项为0{@link ProductType#DEFAULT_TOP_PARENT_ID}) */ @Column(name = "super_type_id") private Long superTypeId; /** 级联查询数据结构 级联查询成功 */ @OneToMany(targetEntity = ProductTypeView.class, fetch = FetchType.LAZY) @JoinColumn(name = "super_type_id", referencedColumnName = "product_type_id") List<ProductTypeView> childProductTypeList = new ArrayList<>(); }
(此为jpa的自关联查询,一对多且自身维护外键,不能同时添加@ManyToOne,否则报错无法启动项目)
--------------项目试用JPA自关联查询,此外附上--------------------------------------
自关联sql查询语句示例:
SELECT
-- pa.id as id,
-- pa.product_type_name AS pa_type_name,
-- pb.parent_id AS parent_id,
-- pb.id as pb_id,
-- pb.product_type_name as pb_type_name
*
FROM
`product_type_view` AS pa
JOIN product_type_view AS pb ON pa.product_type_id=pb.super_type_id