This blog post records a bug encountered in the actual development of the project.
Error background and details
The background of the problem is when a field in the database is of type longtext and JPA mapping is used
/**
* Product Introduction Related URL
*/
@Basic(fetch=LAZY)
@Lob
@Column(name = "goods_introduce",columnDefinition = "longtext")
private String goodsIntroduceUrl;
The error is as follows:
Repeated column in mapping for entity: com.xxx.business.goods.bean.GoodsEntity column: goods_introduce (should be mapped with insert="false" update="false")
The detailed error information is as follows:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.xxx.business.goods.bean.GoodsEntity column: goods_introduce (should be mapped with insert="false" update="false")
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:403)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 16 common frames omitted
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.xxx.business.goods.bean.GoodsEntity column: goods_introduce (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:862)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:880)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:902)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:634)
at org.hibernate.mapping.RootClass.validate(RootClass.java:267)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:351)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:464)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1249)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391)
... 20 common frames omitted
Solution
The problem is that a long text
type field is customized in the database, and then spring data JPA customizes a type, causing duplicate fields.
The solution is very simple, that is to disable the functions of inserting and updating table fields in spring data JPA for this field.
/**
* Product Introduction Related URL
*/
@Basic(fetch=LAZY)
@Lob
@Column(name = "goods_introduce",columnDefinition = "longtext",insertable = false,updatable = false)
private String goodsIntroduceUrl;
Read More:
- When the database table field is set to self incrementing, use the entity class to insert or update the data to solve the error (Hibernate Framework)
- springboot sqlserver druid reward: validateConnection false
- [Solved] Java.util.linkedhashmap cannot be cast to entity class
- [Solved] Mybatis insert Error: Cause: java.sql.SQLException: SQL String cannot be empty
- Ruoyi-cloud Integrated mybatis-plus Error: Unknown column ‘search_value‘ in ‘field list‘
- [Solved] java: Internal error in the mapping processor: java.lang.NullPointerException
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] IDEA Startup Error: java: Internal error in the mapping processor
- [Solved] Mapped Statements collection does not contain value for xxx
- [Solved] Error attempting to get column ‘xxxx_time‘ from result set. Cause: java.sql.SQLFeatureNotSupportedEx
- Springboot integrates Redis annotation and access error: java.io.NotSerializableException: com.demo.entity.MemberEntity
- [Solved] Error creating bean with name ‘entityManagerFactory‘ defined in class path resource
- [Solved] Java.lang.IllegalStateException: Type handler was null on parameter mapping for property ‘__frch_it
- [Solved] JPA Create Sheet error at the First time: Cant DROP [xxx];check that column/key exists
- [Solved] Error updating database. Cause: java.sql.SQLException: Incorrect integer value: ‘**‘ for column
- Mybatis Error: Error instantiating class bakou.entity.Person with invalid types () or value)
- [Solved] Mybatis Error: attempting to get column ‘XX’ from result set
- Rancher application service error: request entity too large
- [Solved] JavaErrors_mybatis collection column Pass Value Error