对象类型JPA映射注释 [英] JPA mapping annotations for Object type

查看:319
本文介绍了对象类型JPA映射注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将实现一个实体类,是这样的:

I will implement an entity class, something like:

@Entity
public class XXXEntity {
     @Id
     private Long id;

     private Object entity;
}

但我不知道如何对象类型字段映射?

But I am not sure how to map the Object type field?

其实,在我的项目的对象类型包含其他几个实体,如A,B,C(全部A,B和C实现Serilizable接口)

Actually, in my project the object types contain several other entities, like A, B, C. (all A,B, and C implement Serilizable interface)

我要标注它作为@Lob,但我不知道它是正确的?因为对象不实现Serilizable接口。

I want to annotate it as @Lob, but I am not sure it is correct? Because Object doesn't implement Serilizable interface.

有关任何想法?谢谢你。

Any ideas about that? Thanks.

推荐答案

没有,这是不正确的用@Lob进行注解。您不能直接标注任意对象作为一个持久属性。 JPA提供商也无从知道如何坚持它。

No, it is not correct to annotate it with @Lob. You cannot directly annotate arbitrary Object as a persistent attribute. JPA provider have no way to know how to persist it.

据JPA 2.0规范持久的属性必须是下列之一:

According JPA 2.0 specification persistent attribute must be one of following:

Java基本类型; java.lang.String中;其他Java序列化类型
  (包括原始类型的包装,
  java.math.BigInteger中,java.math.BigDecimal中,java.util.Date,java.util.Calendar中的[5]
  java.sql.Date,java.sql.Time中,java.sql.Timestamp中,字节[],字节[],
  的char [],字符[]和用户定义的类型实现了
  Serializable接口);枚举;实体类型;实体的集合
  类型;嵌入类;基本和嵌入式类型的集合。

Java primitive types; java.lang.String; other Java serializable types (including wrappers of the primitive types, java.math.BigInteger,java.math.BigDecimal,java.util.Date,java.util.Calendar[5], java.sql.Date, java.sql.Time, java.sql.Timestamp, byte[], Byte[], char[], Character[], and user-defined types that implement the Serializable interface); enums; entity types; collections of entity types; embeddable classes; collections of basic and embeddable types.

您应该重新设计模型这样一种方式,没有必要坚持基本无类型的数据。

You should redesign model such a way that there is no need to persist basically typeless data.

这篇关于对象类型JPA映射注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆