使用Hibernate提取的实体的所有字段均设置为NULL。如何避免这种情况?
这是我的Jpa存储库。

@Repository
public interface PolicyRepository extends JpaRepository<Entity, Long>{
    Entity findByEntSeqNo(@Param("entSeqNo") long entSeqNo);
}


调试后,我可以看到获取的数据位于字段名称$$_hibernate_interceptor

这是我的实体课

@Entity
@Table(name = "ENTITY_TABLE")
@Lazy(value = false)
public class Entity extends AuditModel {

    @Id
    @Column(name = "ENT_SEQ_NO")
    @GeneratedValue(generator="entitySeq")
    @SequenceGenerator(name="entitySeq",sequenceName="\"ENT_SEQ_NO_seq\"", allocationSize=1)
    private long entSeqNo;

    @Column(name = "ENT_CUSTOMER_CODE")
    @NotEmpty(message = "Customer Code is Required.")
    private String entCustomerCode;

    @Column(name = "ENT_CLAS_CODE")
    @NotEmpty(message = "Class Code is Required.")
    private String polcClasCode;

    @Column(name = "ENT_PROD_CODE")
    @NotEmpty(message = "Product Code is Required.")
    private String entProdCode;

    @Column(name = "ENT_BRANCH_CODE")
    @NotEmpty(message = "Branch Code is Required.")
    private String entBranchCode;

    @Column(name = "ENT_YYY_NO")
    @NotEmpty(message = "Yyy Number is Required.")
    private String entYyylNo;

    @Column(name = "ENT_XX_NO")
    private String entXxNo;

    @Column(name = "ENT_XXX_NO")
    private String entXxxNo;

    @Column(name = "ENT_COMMENCEMENT_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date entCommencementDate;

    @Version
    @NotNull(message = "Version is Required.")
    @Column(name = "VERSION")
    private int version;

    @Column(name = "ENT_EXPIRY_DATE")
    @NotNull(message = "Entity Expiry Date is Required.")
    @Temporal(TemporalType.TIMESTAMP)
    private Date entExpiryDate;

    @Column(name = "ENT_DELIVERY_MODE")
    private String entDeliveryMode;

    @Column(name = "ENT_COLLECTED_BY")
    private String entCollectedBy;

    @Column(name = "ENT_COLLECTED_USER_NIC")
    private String entCollectedUserNic;

    @Column(name = "ENT_COLLECTED_USER_MOBILE")
    private String entCollectedUserMobile;

    @Column(name = "ENT_COLLECTED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date entCollectedDate;

    @Column(name = "ENT_POSTED_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date entPostedDate;

    @Column(name = "ENT_POSTED_REF_NO")
    private String entPostedRefNo;

    @Column(name = "ENT_LANG_CODE")
    private String entLangCode;

    @Column(name = "ENT_PP1_ID", insertable = false, updatable = false)
    private Long entPp1Id;

    @Column(name = "ENT_STATUS")
    private Short entStatus;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ENT_PP1_ID", referencedColumnName = "ID")
    private Pp1 entPp1;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ENT_EPP1_ID", referencedColumnName = "ID")
    private Epp1 entEpp1;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "xxx")
    private Collection<TaskLog> taskLogColletion;
}



我在这里问这个问题,因为我找不到此行为的确切原因。所有Jpa操作都工作正常,只有当我尝试从数据库中选择详细信息时,才会发生这种情况。我还尝试了getOne方法,并且发生了相同的问题。

最佳答案

您不需要在jpa界面中使用Entity findByEntSeqNo(@Param("entSeqNo") long entSeqNo);方法,因为entSeqNo是您实体的ID。
因此,当您想通过ID获得一个实体时,只需调用JpaRepository提供的policyRepository.getOne(the value of entSeqNo)

或者您可以使用CrudRepository提供的policyRepository.findById(the value of entSeqNo) whitch基本上是JpaRepository的超级接口

附:请不要在您的界面中覆盖这些方法。

10-04 20:40