java - @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
解决方案
您不能有两个修改同一列的映射idDireccion
。就目前而言,Planta
当前使用修改该列的两个映射进行映射;直接映射:
@Column(name="idDireccion")
private int idDireccion;
和多对一映射:
@ManyToOne(...)
@JoinColumn(name="idDireccion", referencedColumnName="idDireccion")
private Direccion direccion;
您可能想要删除直接映射。
此外,您问题中的错误似乎与此问题无关(“无法找到具有逻辑名称的列:idEmpresa ...”)。还是我误解了你的问题?
推荐阅读
- javascript - 鉴于上传过程是异步的,我如何在将文件上传到 firestore 后获取文件的元数据作为函数的返回值?
- java - 如何在图像视图中加载验证码图像?(热链接验证码)
- json - 如何在 golang 中创建多级地图
- android - 安装调试 APK 时出现 App not installed 错误
- java - 使用 apache poi 和 DFC 在 java 中编写、附加 DQL 查询结果到 excel
- postgresql - 基于postgres数据库的add_months函数报错
- javascript - javascript 无法使用嵌套值映射对象数组
- vba - 根据其他单元格中的条件在相邻单元格中创建命名范围
- javascript - WebAssembly <-> JavaScript 内存交互如何与多个类型化数组一起工作?
- python - 如何每次请求 URL 更改一些数字?