首页 > 解决方案 > @JoinColumn 与具有相同名称 JpaMapping 的列的问题

问题描述

我需要一些指导。我有下一个数据库(对不起,我还不能上传图片)在这个数据库中,一些列具有相同的名称(例如idDireccion),但是在服务器端,外键是这样定义

我遇到的问题是因为 Springboot 正在检测具有相同名称的列,我不知道我在映射数据库时是否遗漏了一些东西。我知道这与列名有关,因为我更改了它们并且它“有效”,但我宁愿不修改数据库结构。

这是Java代码

我想澄清一件事。我不希望程序在数据库中创建或更改任何内容。我只是希望它能够插入和编辑数据。

对不起,如果我不够清楚,英语不是我的主要语言。

这是我得到的错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'iCita' defined in mx.com.interfaces.iCita defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to find column with logical name: idEmpresa in org.hibernate.mapping.Table(Empresa) and its related supertables and secondary tables

标签: javahibernatejpa

解决方案


您不能有两个修改同一列的映射idDireccion。就目前而言,Planta当前使用修改该列的两个映射进行映射;直接映射:

@Column(name="idDireccion")
private int idDireccion;

和多对一映射:

@ManyToOne(...)
@JoinColumn(name="idDireccion", referencedColumnName="idDireccion")
private Direccion direccion;

您可能想要删除直接映射。

此外,您问题中的错误似乎与此问题无关(“无法找到具有逻辑名称的列:idEmpresa ...”)。还是我误解了你的问题?


推荐阅读