Java Sping数据返回空元素的列表,但列表中有很多元素

Java Sping数据返回空元素的列表,但列表中有很多元素,java,spring-boot,jpa,spring-data-jpa,spring-data,Java,Spring Boot,Jpa,Spring Data Jpa,Spring Data,我有个问题 我有两个实体: 实体阿尔贝罗酒店 @Entity @IdClass(Albero.class) @Table(schema="organo", name = "albero") public class Albero implements Serializable { private static final long serialVersionUID = 1L; @Id @JoinColumn(name = "cmu") @OneToOne p

我有个问题

我有两个实体:

实体阿尔贝罗酒店

@Entity 
@IdClass(Albero.class)
@Table(schema="organo", name = "albero")
public class Albero implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @JoinColumn(name = "cmu")
    @OneToOne
private Struttura cmu;

    @Id
    @JoinColumn(name = "padre")
    @NotFound(action = NotFoundAction.IGNORE)
    @ManyToOne 
    private Struttura padre;

    @Column(name = "div")
    private Date div;

@Column(name = "dfv")
private Date dfv;

    @Column(name = "cso", length=15)
    private String cso;

... get and set methods
和实体STRUTTURA

@Entity
@Table(schema="organo", name="strutture")
@SqlResultSetMapping(
        name = "Albero",
        classes =  @ConstructorResult(
                    targetClass = Albero.class,
                    columns = {
                @ColumnResult(name="cmu", type=String.class), 
                    @ColumnResult(name="padre", type=String.class)
                    }
        )       
)
public class Struttura implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "cmu")
    private String cmu; 

    @Column(name = "nome", length=512)
    private String nome;

    @Column(name = "tipologia")
    private String tipologia;

    @Column(name = "data_creazione")
    private Date data_creazione;

 ...get and set methods 
我有一个存储库alberrepository,方法如下:

public List<Albero> findByDfvIsNull();
公共列表findByDfvIsNull();
以及使用本机查询的其他方法:

String QUERY = "SELECT a.* FROM ALBERO a WHERE DFV IS NULL";
@Query(nativeQuery = true, value = QUERY)
public List<Albero> findAllWithDfvIsNull();
String QUERY=“从DFV为空的ALBERO a中选择一个*”;
@查询(nativeQuery=true,value=Query)
公共列表findAllWithDfvIsNull();
查询Oracle数据库,给我一个802记录的结果。 每条记录都已满;它们具有值

相反,Java方法给了我一个802对象列表 但是这些对象是空的

为什么?? 你能帮我吗


非常感谢
@IdClass
注释中的问题。 您需要一个特殊的PK类:

public class AlberPK implements Serializable {
  private static final long serialVersionUID = 1L;

  @Id
  @JoinColumn(name = "cmu")
  @OneToOne
  private Struttura cmu;

  @Id
  @JoinColumn(name = "padre", nullable = true)
  @NotFound(action = NotFoundAction.IGNORE)
  @ManyToOne
  private Struttura padre;
}
。。。并在
Albero.class
中进行一些更改:

@Entity
@IdClass(AlberPK.class)
@Table(schema = "organo", name = "albero")
public class Albero implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  private Struttura cmu;
  @Id
  private Struttura padre;

  ...
}
这必须奏效

我真的不明白-你为什么用复杂的PK?如果可能,请注意数据库结构。这对你将来会有很大帮助