I have an entity which contain polymorphic association to few entities. It definition:
Code:
@Entity
@Table(name = "notifications")
public class Notification implements java.io.Serializable {
//some fields ...
//Polymorphic association
@Any (metaColumn = @Column(name = "target_type"), fetch = FetchType.LAZY)
@AnyMetaDef(idType = "integer", metaType = "string",
metaValues = {
@MetaValue(targetEntity = Task.class, value = "Task"),
@MetaValue(targetEntity = AdminNote.class, value = "AdminNote"),
@MetaValue(targetEntity = UserCancelRequest.class, value = "UserCancelRequest"),
})
@JoinColumn(name = "target_id")
@Getter
@Setter
private NotificationAssociation target;
}
My polymorphic association represented by interface NotificationAssociation:
Code:
public interface NotificationAssociation {
/**
* Return actual type of associated entity
* @return one of {@link NotificationTargetType}
*/
String getTargetType();
/**
* Return associated entity id. Used in queries
* @return target entity id
*/
Integer getTargetId();
}
And this works. But i need an access to target from Notification class in criteria though static metamodel API. My metamodel:
Code:
@StaticMetamodel(Notification.class)
public class Notification_ {
public static volatile SingularAttribute<Notification, Integer> id;
public static volatile SingularAttribute<Notification, Integer> postedById;
public static volatile SingularAttribute<Notification, Integer> adminId;
public static volatile SingularAttribute<Notification, NotificationAssociation> target;
public static volatile SingularAttribute<Notification, Date> hiddenAt;
public static volatile SingularAttribute<Notification, Date> createdAt;
}
But when i test this target is null, and when i get model trough Root#getModel() a target isn't present in attributes list. And my question is can i do so or there is any other solution. Thanks for your help