0
votes

query.getResultList() is failing for the following piece of code.

Query query=EntityManager.createQuery("select m from AbstractGasTrade m");
List<T> resultList = query.getResultList();

It throws following exception

javax.persistence.PersistenceException: org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: com.pse.lib.trading.energy.naturalgas.AbstractGasTrade at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:76) at com.pse.lib.db.dao.GenericDao.findAll(GenericDao.java:68) at com.pse.lib.db.logic.GenericManager.findAll(GenericManager.java:75) at com.pse.lib.db.logic.GenericManager.findAll(GenericManager.java:86) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy29.findAll(Unknown Source) at com.pse.katana.services.possvc.PositionService.createPositionSegment(PositionService.java:180) at com.pse.katana.services.possvc.PositionService.handlePositionSubscription(PositionService.java:150) at com.pse.katana.services.possvc.PositionService.accept(PositionService.java:243) at com.pse.katana.messages.PositionSubscriptionRequest.visit(PositionSubscriptionRequest.java:43) at com.pse.katana.services.possvc.PositionService.dispatch(PositionService.java:266) at com.pse.lib.servicengine.processor.AsynchronousOperation.run(AsynchronousOperation.java:42) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) Caused by: org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: com.pse.lib.trading.energy.naturalgas.AbstractGasTrade at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:101) at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:123) at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:374) at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3634) at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1302) at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1291) at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1323) at org.hibernate.loader.Loader.getRow(Loader.java:1230) at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603) at org.hibernate.loader.Loader.doQuery(Loader.java:724) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) at org.hibernate.loader.Loader.doList(Loader.java:2228) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125) at org.hibernate.loader.Loader.list(Loader.java:2120) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67) ... 23 more

It happens when one of the joined column has null value.

@JoinColumn(name = "PayDescriptor")
@ManyToOne(cascade = CascadeType.ALL)
private GasTradeDescriptor tradePriceDescriptor;

Problem is that we want to ignore the values for which joined column has null values and want to continue loading remaining non-null values. For null values we just want to log the message. We are not sure about the best possible approach to tackle this. Any idea or suggestion about the best approach will be much appreciated.

Many thanks in advance.

Rab

1
can you please paste the "PayDescriptor" field annotations.Asad Rasheed
Thanks for your reply. Rab and I work on the same team. Let me clarify a bit: his intention is to continue loading ALL rows even if one single row had an error which is this case. We control as best we can the integrity of the data, but there are tens of thousands of rows. For this and other reasons, the chances of one row having an error are high. I'd think that hibernate has a mechanism to delegate error handling of a single row and keep going? Any ideas?user723780
Are you suggesting that we should traverse the hierarchy tree for AbstractGasTrade ? We can do this. But it seems it'd solve this problem specifically. Our intention is to continue loading all rows whether we encounter this type of error or any other. Right now, we'd fail to load tens of thousands of rows because a single one failed. Not robust.user723780
repeating Stevi Deter a bit, is this class abstract?Jim

1 Answers

1
votes

As the exception states, you cannot instantiate an abstract class. You didn't include the code for AbstractGasTrade but the name sure hints that it is, in fact, abstract.

You need to create the query for one of its concrete children.