我在表中有“ iddId”(主键)列和“ idd_id”(未使用列)。当我尝试执行
通过Spring Data JPA的'findAll'方法,我在创建的对象中得到了空的'iddId'字段,因为休眠查询看起来像:
select 'idd0_.idd_id as col_0_0_'...
我尝试使用@Column(name =“ iddId”)注释手动映射字段,但未进行任何更改。然后,我尝试向实体'idd_id'添加一个附加字段,该实体以@Column(name =“ idd_id)注释,并收到异常:
'org.hibernate.DuplicateMappingException: Table [idd] contains physical column name [idd_id] referred to by multiple logical column names: [idd_id], [iddId]'.
是否可以这样查询:“将idd0_.iddId选择为col_0_0_”?
public class Idd {
@Id
@Column(name = "iddId")
private String iddId;
@Column(name = "idd_id")
private String idd_id;
}
MySQL的:5.7.28
春季数据:2.2.2
最佳答案
只需添加:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
到application.properties