【问题标题】:Issue with @JoinColumn with columns with the same name JpaMapping@JoinColumn 与具有相同名称 JpaMapping 的列的问题
【发布时间】:2021-04-04 06:47:44
【问题描述】:

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

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

Here'sJava 代码

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

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

这是我遇到的错误。

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

【问题讨论】:

  • 能否添加“Empresa”类来检查是否有问题?

标签: java hibernate jpa


【解决方案1】:

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

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

以及多对一映射:

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

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

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

【讨论】:

  • 你是正确的直接映射,对不起我错过了:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-10
  • 1970-01-01
  • 1970-01-01
  • 2017-05-27
  • 2022-07-06
  • 2014-07-17
  • 1970-01-01
相关资源
最近更新 更多