我正在使用Eclipselink设置JPA域模型。在进入实际的@Entity类之前,我已经使用多个@MappedSuperclass类构建了这些模型。执行条件查询时,出现以下错误:
org.springframework.dao.InvalidDataAccessApiUsageException: The attribute [null] is not present in the managed type [EntityTypeImpl@2123492724:DogEntity [ javaType: class com.fake.fake.entity.DogEntity descriptor: RelationalDescriptor(com.fake.fake.entity.DogEntity --> [DatabaseTable(Dog)]), mappings: 22]].;
@MappedSuperclass
public abstract class AbstractBaseEntity {
@Id
@Column(name = "id")
protected String id;
@Column(name = "lastUpdated")
@Temporal(TemporalType.TIMESTAMP)
protected Date lastUpdated;
}
@MappedSuperclass
public abstract class PetImpl extends AbstractBaseEntity implements Pet {
// I pretty much use this class to implement some of Pet
// and add some shared transient fields
@Transient
protected List<String> tags;
@Override
public List<String> getTags() {
return tags;
}
// I have some abstract methods in here also
public abstract int getMaxTags();
}
@Entity
public class DogEntity extends PetImpl {
@Column(name = "breed")
private String breed;
@Override
public int getMaxTags() {
return 1;
}
}
完整的Stacktrace(如果造成混淆,请您道歉,并尝试去除企业特定的条款)
org.springframework.dao.InvalidDataAccessApiUsageException: The attribute [null] is not present in the managed type [EntityTypeImpl@909914828:DogEntity [ javaType: class com.fake.fake.entity.DogEntity descriptor: RelationalDescriptor(com.fake.fake.entity.DogEntity --> [DatabaseTable(Dog)]), mappings: 22]].; nested exception is java.lang.IllegalArgumentException: The attribute [null] is not present in the managed type [EntityTypeImpl@909914828:DogEntity [ javaType: class com.fake.fake.entity.DogEntity descriptor: RelationalDescriptor(com.fake.fake.entity.DogEntity --> [DatabaseTable(Dog)]), mappings: 22]].
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384) ~[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:418) ~[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.11.3.RELEASE.jar:?]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.3.RELEASE.jar:?]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
我希望在每个超级类上都具有@MappedSuperclass会很好,但是似乎存在一些无法真正诊断的问题,因为它只是说我具有一些[null]属性。