-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Polymorphic association and static metamodel api
PostPosted: Thu Sep 24, 2015 5:58 am 
Newbie

Joined: Thu Sep 24, 2015 5:55 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Polymorphic association and static metamodel api
PostPosted: Thu Sep 24, 2015 8:37 am 
Newbie

Joined: Thu Sep 24, 2015 5:55 am
Posts: 2
Think I figure it out. An @Any annotation and related to it (@AnyMetadef and other) provides by Hibernate, not JPA. So we can't use JPA Criteria API to manage this kind of relations, but we can use Hibernate Criteria API instead.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.