Hi,
When will this be fixed please? I've checked the AnyType.java code in the ORM 4.3.4.Final version and the fix is not there . ( I need the Any type to work properly as i am using this as a workaround to another Hibernate missing feature that is the interface polymorphic mapping . )
Furthermore, a HQL query to load the corresponding @Any field returns the entity instance and not the field instance. e.g. "select e.field from Entity e where e.id=..." returns the 'e' instance instead of the field value. A workaround consists of using the criteria api with a property projection.
So as a workaround for both Any type issues, i wrote a Java code (with some unexpected results - see code comments below) that loads the entity and for the @Any field queries the database using the Criteria api and sets the field value:
Object fieldValue=null; ProjectionList fieldProjection = Projections.projectionList().add(Projections.property(fieldName), fieldName);
// Read the field value from the database. This value will be returned as a Hibernate proxy (weird!) Criteria criteria =session.createCriteria(classs).setProjection(fieldProjection).add(Restrictions.eq("id", id)); List list = criteria.list(); if (!list.isEmpty()) { fieldValue = list.get(0); // The value seems to be read as a Hibernate proxy that has actually been initialized! The //code below will extract the initialized value (weird code!) if (fieldValue instanceof HibernateProxy) { HibernateProxy hibernateProxy = (HibernateProxy) fieldValue; LazyInitializer hibernateLazyInitializer = hibernateProxy.getHibernateLazyInitializer(); fieldValue = hibernateLazyInitializer.getImplementation(); } } ...Set the field value in the entity instance ...
Thank you.
|