开发者

JPA generic field

Is it possible to persist a generic field?

I have this property on an Entity class

...
private T payload;
...

T extends EventMessagePayload

and

public interface StringPayload extends EventMessagePayload{ 
    String getPayload();
}

In my application i persist the field only when is of String type and during the save operation all works great.

When I read the object instead JPA try to create a 开发者_开发技巧String object but instead is a StringPaylod. Is there a way to intercept the creation and handle the object marshalling?


JPA itself does not allow this, but your JPA implementation might allow it. We once did this with Hibernate, and it boilds down to implement your own EntityTuplizer (and a HibernateInterceptor to map your objects back to HibernateEntities).


We can. if the T implements Serializable

@Entity
public class IgsSubject extends BasicObject implements Serializable{

    private static final long serialVersionUID = -5387429446192609471L;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜