I have this class structure:
@Entity
@Table(name="BigEvent")
@DiscriminatorColumn(name = "type")
public class GridListEvent extends BigEvent implements Serializable{
@OneToOne(cascade=CascadeType.ALL)
@EventBody
private GridListEventBody ogmEventBody;
...
}
@Entity
@Table(name="GridListEventBody")
public class GridListEventBody implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@GridFSBucket("gridlist")
GridFS gridlist;
...
}
A jpql query like this works
Query query = mdm.getEntityManager().createQuery("FROM GridListEvent e WHERE e.id=:id").query.setParameter("id",1L);
If I want to select all the entities it doesn’t with the error in title
Query query = mdm.getEntityManager().createQuery("SELECT e FROM GridListEvent e");
As you can see the GridFS
field is in Body entity, I query for the main entity GridListEvent
.
I noticed it works if I move the GridFS
field in GridListEvent
but I dont’ need that.
This is the stacktrace
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: OGM000080: Could not load an entity batch: [com.actor.jpa.GridListEventBody#<2, 4>]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1514)
at org.hibernate.query.Query.getResultList(Query.java:135)
at com.actor.benchmark.gridfs.Select.main(Select.java:39)
Caused by: org.hibernate.HibernateException: OGM000080: Could not load an entity batch: [com.actor.jpa.GridListEventBody#<2, 4>]
at org.hibernate.ogm.loader.impl.OgmLoader.loadEntityBatch(OgmLoader.java:1324)
at org.hibernate.ogm.loader.entity.impl.BatchingEntityLoader.doBatchLoad(BatchingEntityLoader.java:99)
at org.hibernate.ogm.loader.entity.impl.DynamicBatchingEntityLoaderBuilder$DynamicBatchingEntityLoader.load(DynamicBatchingEntityLoaderBuilder.java:124)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4269)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:511)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:481)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:222)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:281)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:124)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:92)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1257)
at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1140)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:682)
at org.hibernate.type.EntityType.resolve(EntityType.java:464)
at org.hibernate.type.ManyToOneType.resolve(ManyToOneType.java:239)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:172)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.ogm.loader.impl.OgmLoader.initializeEntitiesAndCollections(OgmLoader.java:810)
at org.hibernate.ogm.loader.impl.OgmLoader.doQuery(OgmLoader.java:394)
at org.hibernate.ogm.loader.impl.OgmLoader.doQueryAndInitializeNonLazyCollections(OgmLoader.java:284)
at org.hibernate.ogm.loader.impl.OgmLoader.loadEntity(OgmLoader.java:202)
at org.hibernate.ogm.loader.impl.OgmLoader.loadEntitiesFromTuples(OgmLoader.java:221)
at org.hibernate.ogm.loader.entity.impl.DynamicBatchingEntityLoaderBuilder$DynamicBatchingEntityLoader.loadEntitiesFromTuples(DynamicBatchingEntityLoaderBuilder.java:129)
at org.hibernate.ogm.query.impl.OgmQueryLoader.listOfEntities(OgmQueryLoader.java:92)
at org.hibernate.ogm.query.impl.OgmQueryLoader.list(OgmQueryLoader.java:78)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
at org.hibernate.ogm.query.impl.OgmQueryTranslator.list(OgmQueryTranslator.java:130)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
... 2 more
Caused by: org.hibernate.PropertyAccessException: Could not set field value [5c4dd4f3c0f6832d6caba88f] value by reflection : [class com.actor.jpa.GridListEventBody.gridlist] setter of com.actor.jpa.GridListEventBody.gridlist
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:61)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:649)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:205)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4903)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:190)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
at org.hibernate.ogm.loader.impl.OgmLoader.initializeEntitiesAndCollections(OgmLoader.java:810)
at org.hibernate.ogm.loader.impl.OgmLoader.doQuery(OgmLoader.java:394)
at org.hibernate.ogm.loader.impl.OgmLoader.doQueryAndInitializeNonLazyCollections(OgmLoader.java:284)
at org.hibernate.ogm.loader.impl.OgmLoader.loadEntityBatch(OgmLoader.java:1321)
... 32 more
Caused by: java.lang.IllegalArgumentException: Can not set org.hibernate.ogm.datastore.mongodb.type.GridFS field com.actor.jpa.GridListEventBody.gridlist to org.bson.types.ObjectId
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.base/java.lang.reflect.Field.set(Field.java:780)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:41)
... 41 more