Issue
I need some guidance here. I have the next database (sorry, I can't upload images yet) In this database, some columns have the same name (idDireccion for example), but in the server side, the foreign key is defined like this.
The problem I'm getting is because Springboot is detecting the columns have the same name, I don´t know if I'm missing something at mapping the database. I know it's about the column names because I change them and it "works" but I rather not to modify the database structure.
Here's the Java code
I want to clarify something. I don't want the program to create or alter anything in the database. I just want it to be able to insert and edit data.
Sorry if I'm not clear enough, English is not my main language.
Here's the error I'm getting.
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
Solution
You cannot have two mappings that modify the same column idDireccion
. As it stands, Planta
is currently mapped with two mappings that modify that column; the direct mapping:
@Column(name="idDireccion")
private int idDireccion;
and the many-to-one mapping:
@ManyToOne(...)
@JoinColumn(name="idDireccion", referencedColumnName="idDireccion")
private Direccion direccion;
You probably want to remove the direct mapping.
Also, the error in your question seems unrelated to this problem ("Unable to find column with logical name: idEmpresa..."). Or am I misunderstanding your question?
Answered By - Brian Vosburgh