У меня есть требование иметь абстрактный суперкласс.
У меня есть 6 подклассов для этого абстрактного суперкласса.
Я сопоставил их с помощью стратегии наследования SINGLE_TABLE в JPA.
В другом POJO у меня отношения один ко многим с этими 1 + 6 классами.
@OneToMany(mappedBy = "mSearchPreference", cascade = CascadeType.ALL)
private Set<SearchCriteria> mSearchCriteria;
здесь "SearchCriteria" является абстрактным классом.
@Entity
@Table(name = "SRCH_CRTR_T", schema = "LPEW")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "SRCH_DISCRIMINATOR_CDE", discriminatorType = DiscriminatorType.STRING)
@org.hibernate.annotations.ForceDiscriminator
public abstract class SearchCriteria extends BaseDBObject implements Comparable<SearchCriteria>
и имеет 6 конкретных классов подклассов, таких как
@Entity
@DiscriminatorValue("DATE")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class SearchCriteriaDateRange extends SearchCriteria
Я могу вставить значения в таблицу, но при получении я получаю сообщение об ошибке:
Caused by: org.hibernate.WrongClassException: Object with id: 261 was not of the specified subclass: com.lmig.lit.lpew.model.criteria.SearchCriteria (Discriminator: DATE )
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1453)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1284)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.L
10:57:44,786 INFO [STDOUT] oader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
at org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:52)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readElementExistence(AbstractPersistentCollection.java:142)
at org.hibernate.collection.PersistentSet.add(PersistentSet.java:187)
at com.lmig.lit.lpew.model.homescreen.HomeScreenPreference.addSearchCriteriaByType(HomeScreenPreference.java:132)
at com.lmig.lit.lpew.model.homescreen.HomeScreenPreference.addSearchCriteriaByType(HomeScreenPreference.java:147)
at com.lmig.lit.lpew.service.LpewUserServiceImpl.initializeHomeScreenPreferences(LpewUserServiceImpl.java:135)
at com.lmig.lit.lpew.service.LpewUserServiceImpl.findUserAndInitialize(LpewUserServiceImpl.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy122.findUserAndInitialize(Unknown Source)
at com.lmig.lit.lpew.jsf.beans.UserSession.getLpewUser(UserSession.java:989)
at com.lmig.lit.lpew.jsf.beans.RequestForServiceBean.getAllRequests(RequestForServiceBean.java:263)
at com.lmig.lit.lpew.jsf.beans.RequestForServiceBean.getAllNewRequests(RequestForServiceBean.java:382)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
Кто-нибудь знает решение?