2 Replies Latest reply on Jun 27, 2013 12:09 PM by Adam Warski

    How can i write a query on @Any annotated attributes in hibernate4 supported model class.

    Jagadheeswar Sarma Kappaganthu Newbie

      Hi I am using Hibernate4 in my application.


      I am using @Any annotation. Now my requirement is to write a join query.





      public class TagMapping extends Persistent {



           private Taggable taggable;



           @Any(metaColumn = @Column(name = "taggable_type"))

           @AnyMetaDef(idType = "long", metaType = "string",

                metaValues = {

                     @MetaValue(targetEntity = com.myorg.model.tags.ServiceGroup.class, value = "SERVICEGROUP"),

                     @MetaValue(targetEntity = com.myorg.model.device.Device.class, value = "DEVICE")



            public Taggable getTaggable() {

                return taggable;








      public interface Taggable {



           * @return the persisted Id of a taggable entity


          public abstract long getId();



           * @return the name of the taggable entity


          public abstract String getName();



           * @return the class name of the taggable entity


          public abstract String getEntityType();



      And com.myorg.model.tags.ServiceGroup.class and com.myorg.model.device.Device.class are the two model classes which implements the Taggable interface.


      Now can i write a Hibernate Criteria query to get the attributes of a Taggable element.

      While i am trying to get the attributes by joining, i am getting an exception like unable to cast any type to component type.

      Do i have any api for above requirement.

      My requirement is to join TagMapping and Device or ServiceGroup