开发者

Embedding Generic Types in JPA

Does JPA support embedding a class attribute whose type is a parameterized generic or java.lang.Object? For example:

public class Foo<T>;
{
   private T      param1;
   private Object param2;
}

I have a use case where I have a class that "w开发者_运维问答raps" some arbitrary class (the generic T or java.lang.Object) via aggregation plus contains primitive types representing metadata about the wrapped object.

In this case, I'd like there to be DB tables for each of things being wrapped that also contain columns for the metadata. These metadata columns would be duplicated across all tables representing the wrapped embedded objects.


I'd like there to be DB tables for each of things being wrapped that also contain columns for the metadata. These metadata columns would be duplicated across all tables representing the wrapped embedded objects.

You could maybe persist Object or T as a @Lob but I don't think that the above is possible, I don't see how you could express the mappings, how a JPA provider could be aware of the tables.

See also

  • Enterprise JavaBeans - JPA Generic entities classes Mappedsuperclass are not possible!
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜