Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPA getReference在我的对象中设置了错误的id(始终设置为零)_Java_Jpa - Fatal编程技术网

Java JPA getReference在我的对象中设置了错误的id(始终设置为零)

Java JPA getReference在我的对象中设置了错误的id(始终设置为零),java,jpa,Java,Jpa,我使用的是JPAEntityManager.getReference(Class clazz,Integer pk)。 我知道pkvalue被设置为1,但在方法返回的对象中,该值仍然被设置为零。我不明白为什么 这是我的密码: @Component public class TypeDAO extends MainDAO { public TypeDTO simpleProxyRetrieveByIdType(int id){ TypeDTO type = simpleP

我使用的是JPA
EntityManager.getReference(Class clazz,Integer pk)
。 我知道
pk
value被设置为1,但在方法返回的对象中,该值仍然被设置为零。我不明白为什么

这是我的密码:

@Component
public class TypeDAO extends MainDAO {

    public TypeDTO simpleProxyRetrieveByIdType(int id){
        TypeDTO type = simpleProxyRetrieveById(TypeDTO.class, id);
        return type;
    }
}
我的
MainDAO
课程:

static protected <E> E simpleProxyRetrieveById(Class <E> clazz, Integer id) {
    EntityManager em = emFactory.createEntityManager();
    E item = em.getReference(clazz, id);
    em.close();
    return item;
}
@Entity
@Table(name = "type_livr")
public class TypeDTO {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "type_livraison_id")
    private int id;
        public int getId() {return id;}
        public void setId(int id) {this.id = id;}

    @Column(name = "code")
    private int code;
    public int getCode() {return code;}
    public void setCode(int code) {this.code = code;}

    @Column(name = "libelle_court")
    private String libelleCourt;
        public String getLibelleCourt() {return libelleCourt;}
        public void setLibelleCourt(String libelleCourt) {this.libelleCourt = libelleCourt;}

    @Column(name = "libelle_long")
    private String libelleLong;
        public String getLibelleLong() {return libelleLong;}
        public void setLibelleLong(String libelleLong) {this.libelleLong = libelleLong;}

    @OneToMany(mappedBy = "type")
    private List<LivraisonDTO> typeLivr;
        public List<LivraisonDTO> getTypeLivr() {return typeLivr;}
        public void setTypeLivr(List<LivraisonDTO> typeLivr) {this.typeLivr = typeLivr;}

    public TypeDTO() {
    }

    public TypeDTO(int id, int code, String libelleCourt, String libelleLong) {
        this.id = id;
        this.code = code;
        this.libelleCourt = libelleCourt;
        this.libelleLong = libelleLong;
    }   
}

谢谢您的回答。

事实上没有问题:

在调用getId()getter之前,id不会真正初始化为真实id


您应该只签入调试器

事实上没有问题:

在调用getId()getter之前,id不会真正初始化为真实id

您应该只签入调试器