There is an entity
public class RealEstateType { private long customer_id; private String name; private Customer customerByCustomerId; @Id @Column(name = "customer_id", insertable = false, updatable = false) public long getCustomerId() { return customer_id; } public void setCustomerId(long id) { this.customer_id = id; } which describes the table
CREATE TABLE db.real_estate_type ( customer_id BIGINT NOT NULL, name CHARACTER VARYING(255), FOREIGN KEY (customer_id) REFERENCES db.customer (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ); Which customer_id is FOREIGN KEY
Hibernate throws an exception when @Column(name = "customer_id") , @Column(name = "customer_id", insertable = false, updatable = false) , @Column(name = "customer_id", insertable = true, updatable = false)
amework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: hibernate.model.df.RealEstateType column: customer_id (should be mapped with insert="false" update="false") at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) But if you delete customer_id and PK to make @Id @Column(name = "name") , then everything works.
If we leave customer_id and PK to make @Id @Column(name = "name") , then we get the same error.
Explain to me the reason for this behavior and how to solve it?