简体   繁体   中英

jpa repository returns incomplete records

i've written a very simple jpaRepository for a very simple table, when i call my method to fetch records by a filtering column i get two results but the second one looks incomplete somehow as the table had a single column. this is the mapping entity

@Entity
@Table(name="TE106_SEC")
public class Section {
    
    @Id
    @Column(name = "N_REV_ID")
    private Long revision;
    @Column(name = "N_CPR_PIT")
    private Integer N_CPR_PIT;
    @Column(name = "C_POR")
    private String C_POR;
    @Column(name = "N_PRG")
    private Integer N_PRG;
    @Column(name = "C_SID_STR_TYP")
    private String C_SID_STR_TYP;

    public Long getRevision() {
        return revision;
    }

    public void setRevision(Long revision) {
        this.revision = revision;
    }

    public Integer getN_CPR_PIT() {
        return N_CPR_PIT;
    }

    public void setN_CPR_PIT(Integer n_CPR_PIT) {
        N_CPR_PIT = n_CPR_PIT;
    }

    public String getC_POR() {
        return C_POR;
    }

    public void setC_POR(String c_POR) {
        C_POR = c_POR;
    }

    public Integer getN_PRG() {
        return N_PRG;
    }

    public void setN_PRG(Integer n_PRG) {
        N_PRG = n_PRG;
    }

    public String getC_SID_STR_TYP() {
        return C_SID_STR_TYP;
    }

    public void setC_SID_STR_TYP(String c_SID_STR_TYP) {
        C_SID_STR_TYP = c_SID_STR_TYP;
    }
    
} 

this is the repository

package repository.reportmanager;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;

import model.entity.Section;

public interface ProjectSectionRepository extends JpaRepository<Section, Long>{
    
    List<Section> findByRevision(Long revision);

}

these are the debugging informations, the generated query works fine if executed un a db client (dbeaver in my case)

        select
            section0_.n_rev_id as n_rev_id1_4_,
            section0_.c_por as c_por2_4_,
            section0_.c_sid_str_typ as c_sid_str_typ3_4_,
            section0_.n_cpr_pit as n_cpr_pit4_4_,
            section0_.n_prg as n_prg5_4_ 
        from
            te106_sec section0_ 
        where
            section0_.n_rev_id=6700
    2020-12-16 14:39:22.874 TRACE 11424 --- [nio-9081-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([n_rev_id1_4_] : [BIGINT]) - [6700]
    2020-12-16 14:39:22.883 TRACE 11424 --- [nio-9081-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([c_por2_4_] : [VARCHAR]) - [A]
    2020-12-16 14:39:22.889 TRACE 11424 --- [nio-9081-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([c_sid_str_typ3_4_] : [VARCHAR]) - [null]
    2020-12-16 14:39:22.894 TRACE 11424 --- [nio-9081-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([n_cpr_pit4_4_] : [INTEGER]) - [1]
    2020-12-16 14:39:22.899 TRACE 11424 --- [nio-9081-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([n_prg5_4_] : [INTEGER]) - [1]
    2020-12-16 14:39:22.904 TRACE 11424 --- [nio-9081-exec-4] o.h.type.descriptor.sql.BasicExtractor   : extracted value ([n_rev_id1_4_] : [BIGINT]) - [6700] 
**--- second records ends here ---------------------------------------------**

i've tried to add a Query attribute to the method, define the query as native, call the findAll default method with an Example entity. Nothing changes. I cannot see anything wrong in my code

My mistake, as M. Deinum has spotted, i have misconfigured my entity. The table has a composite pk while i thought it had simple sequence. So my guess is jpa generate a correct query but when it emits the list of results it finds two records with a duplicated pk and do not fully extract the second record.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM