为什么从hibernate返回的对象列表是空的?

时间:2015-03-20 23:21:01

标签: hibernate jpa

好吧,我又来了。在我工作的项目中,我遇到了一个问题,同时我用另一种方式来解决它。但在ManyToMany的关系中,我不知道如何做到。当我使用EntityManager的find方法并且它返回了一个对象时,如果这个对象有一个其他对象的列表,即使我保存了填充列表的对象,有时这个列表也会变空。

课程:

public class EquipeCategoria {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Integer id;
    private ESexo sexo;
    private ECategoria categoria;
    @ManyToOne(cascade = CascadeType.ALL)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private Equipe equipe;
    @OneToOne(cascade = CascadeType.ALL)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private EquipeJogo equipeJogo;
    @ManyToMany(cascade = CascadeType.ALL)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<Dirigente> dirigentes;
    @OneToMany(cascade = CascadeType.ALL)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<Atleta> atletas;
    @ManyToOne
    private Modalidade modalidade;
    @ManyToOne
    private Prova prova;
    // getters and setters
}

public class Dirigente {

    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Integer id;
    private String doc_prof;
    private String nome;
    private EFuncao funcao; // EFuncao
    @ManyToMany(cascade = CascadeType.ALL)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<EquipeCategoria> equipes;
    @ManyToOne
    private Equipe equipe;
    // getters and setters
}

我该怎么办?

0 个答案:

没有答案