Using hibernate @Any mapping to map multiple entities in the same, I haven't be able to build a request to fetch all the objects of a specific class.
Hibernate doesn't seems to be capable to handle this kind of request.
My application doesn't start and throw the following error :
Invocation of init method failed; nested exception is java.lang.ClassCastException: org.hibernate.type.AnyType cannot be cast to org.hibernate.type.ComponentType
removing the part "left join fetch ic.item i" solve this error.
@Entity @NamedQueries({ @NamedQuery(name = "GET_ITEMS", query = "from ItemContainer ic left join fetch ic.item i where ic.id=:containerId and ic.class=:clazz")}) public class ItemContainer { .... @Any(metaColumn = @Column(name = "TYPE"), fetch = FetchType.LAZY) @AnyMetaDef(idType = "long", metaType = "string", metaValues = { @MetaValue(targetEntity = Item1.class, value = "I1") }) @JoinColumn(name = "TYPE_ID") private IItem item; ... }
(Item1 implements IItem)
@Override @SuppressWarnings("unchecked") public List<ItemContainer> getItem1s(final Long containerId) { return getHibernateTemplate().findByNamedQueryAndNamedParam("GET_ITEMS", new String[] { "containerId", "clazz" }, new Object[] { containerId, Item1.class }); }
:/
Any ideas ?