1

我有一个抽象的超类“视图”

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="tipo", length=1)
public abstract class View extends DefaultModel implements Serializable{
    private static final long serialVersionUID = -4850147998379161237L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    ...

    public abstract List<Institution> getInstitutions();
}

儿童机构班

@Entity
@DiscriminatorValue("1")
public class Institution extends View implements Serializable {
    private static final long serialVersionUID = -18542249993446160L;

    @Override
    @JsonIgnore
    public List<Institution> getInstitutions() {
        return Lists.newArrayList(this);
    }

}

和一个儿童团体

@Entity
@DiscriminatorValue("2")
public class GroupInstitution extends View {
    private static final long serialVersionUID = -6552513217676651258L;

    @ManyToMany
    List<Institution> institutions = new LinkedList<>();

    @Override
    @JsonIgnore
    public List<Institution> getInstitutions() {
        return institutions;
    }
}

我保存了 3 个机构。好的。我试图用这三个机构拯救一个团体。这创建了一个新视图(类型 = 2)。但是关系表是这样的:

2, 1
2, 2
2, 3

即用DiscriminatorValue代替GroupInstitution.id(我把DiscriminatorValue改成3,只是测试,关系是用3做的)

注释是错误的?

4

0 回答 0