如何在复合PK中使用@JsonIdentityInfo? [英] How to use @JsonIdentityInfo with composite PK?

查看:182
本文介绍了如何在复合PK中使用@JsonIdentityInfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的班级有一个 @Id 字段,我可以使用 @JsonIdentityInfo 这样:

If I have a class with a single @Id field I can use @JsonIdentityInfo like this:

@Entity
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
class Example {

    @Id
    int id;
    // getter setter
}

但是如果我有一个复合PK类:

But if I have a composite PK class:

@Entity
@IdClass(value = PointID.class)
public class Point {

    @Id
    private int x;
    @Id
    private int y;
}

@SuppressWarnings("serial")
class PointID  implements Serializable {
    int x, y;
}

如何使用注释?在上面的例子中,用法将是这样的

How do I use the annotation? In the above case the usage will be something like this

Point p = new Point(1,1);
object1.setPoint(p);
object2.setPoint(p);
bigObject.add(object1, object2);

当我序列化 bigObject 我不知道我想重复点数据但是使用它的id与第一个例子一样。

and when I serialize bigObject I don't want to duplciate the point data but use its id like it does with the first example.

推荐答案

似乎<$ c根据我的尝试和在线研究,$ c> @JsonIdentityInfo 不适用于复合PK。

It seems that @JsonIdentityInfo does not work with composite PK according to my attempts and online research.

这篇关于如何在复合PK中使用@JsonIdentityInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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