我搜索过,但没有发现任何问题,我有。 它是另一个hibernate MappingException:实体映射中的重复列
我想要映射一些实体。 AbstractReaction有一个受保护的String:text。每个子实体都必须为此制作自定义getter和setter方法。 相关代码:
AbstractReaction:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class AbstractReaction extends LongId {
protected String text;
public abstract String getText();
public abstract void setText(String text);
...
}
ImageReaction:
@Entity
@Table(name = "image_reaction")
public class ImageReaction extends AbstractReaction {
...
@Override
@NotNull
@Size(max = 2000)
@Column(nullable = false, name = "text", length = 2000)
public String getText() {
return text;
}
@Override
public void setText(String text) {
this.text = text;
}
...
}
LinkReaction:
@Entity
@Table(name = "link_reaction")
public class LinkReaction extends AbstractReaction {
...
@Override
@NotNull
@Size(max = 2048)
@Column(nullable = false, name = "text", length = 2048)
public String getText() {
return text;
}
@Override
public void setText(String text) {
this.text = text;
}
}
在spring entityFactory创建时,我得到以下异常:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1225)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:119)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:853)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 40 more
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.projectaim.model.entity.reaction.ImageReaction column: text (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:709)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:731)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:753)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:506)
at org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:64)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1358)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
... 49 more
我应该如何以面向对象的方式管理'text',以避免这种异常?