找不到任何属性SpringBoot JPA

问题描述

我在运行该应用程序时遇到了这个错误,我不明白为什么。.我在网上找到了信息,但不明白出了什么问题。感谢您的帮助。

2)关于此的另一个问题,我应该提出:

List<HistoriqueDeploiement> findByIdNamespaceAndIdService(Namespace id_namespace,Service id_service);
Or
List<HistoriqueDeploiement> findByIdNamespaceAndIdService(Integer id_namespace,Integer id_service);

错误

Error creating bean with name 'checkConfigDeploiementRepository': factorybean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.example.jpa.repository.CheckConfigDeploiementRepository.findByIdNamespaceAndIdService(com.example.jpa.model.Namespace,com.example.jpa.model.Service)! No property namespace found for type Integer! Traversed path: CheckConfigDeploiement.id.

实体:

@Entity
@Table(name = "historiquedeploiement")
@Data
@EqualsAndHashCode(callSuper=false)
@NoArgsConstructor
@AllArgsConstructor
public class HistoriqueDeploiement extends AuditModel {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id",nullable=false,unique=true)
    private Integer id;    

    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "id_namespace",nullable = false)    
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class,property="id")
    @JsonIdentityReference(alwaysAsId=true)
    @JsonProperty("id_namespace")
    private Namespace namespace;

    @ManyToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "id_service",property="id")
    @JsonIdentityReference(alwaysAsId=true)
    @JsonProperty("id_service")
    private Service service;

    @NotEmpty(message = "Le GitCommit ne peut être vide")
    @Size(max = 255)
    private String gitCommit;   
    
    @NotEmpty(message = "Le TagVersion ne peut être vide")
    @Size(max = 100)
    private String tagVersion;  
    
    @NotEmpty(message = "Le Actionby ne peut être vide")
    @Size(max = 255)
    private String actionBy;    
    
}

NamespaceEntity(与服务相同。)

@Entity
@Table(name = "namespace")
@Data
@EqualsAndHashCode(callSuper=false)
@NoArgsConstructor
@AllArgsConstructor
public class Namespace extends AuditModel {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="id",unique=true)
    private Integer id;

    @NotEmpty
    @Size(max = 100)
    @Column(unique = true)
    private String namespace;

    @OnetoMany(mappedBy = "namespace",cascade = CascadeType.ALL,orphanRemoval = true)  
    private List<HistoriqueDeploiement> historiquedeploiements = new ArrayList<>();

    public void addHistoriqueDeploiement(HistoriqueDeploiement historiquedeploiement) {
        historiquedeploiements.add(historiquedeploiement);
        historiquedeploiement.setNamespace(this);
    }

    public void removeHistoriqueDeploiement(HistoriqueDeploiement historiquedeploiement) {
        historiquedeploiements.remove(historiquedeploiement);
        historiquedeploiement.setNamespace(null);
    }
}

回购协议,我不明白自己在做什么错:

...
@Repository
public interface HistoriqueDeploiementRepository extends JpaRepository<HistoriqueDeploiement,Integer> {        
    List<HistoriqueDeploiement> findAll();
    
    List<HistoriqueDeploiement> findByIdNamespace(Integer id);
    
    List<HistoriqueDeploiement> findByIdNamespaceAndIdService(Namespace id_namespace,Service id_service);
    
    List<HistoriqueDeploiement> findByIdNamespaceAndLogCreatedAtBetween(Namespace id_namespace,Date datedebut,Date datefin);

    List<HistoriqueDeploiement> findByIdNamespaceAndLogCreatedAt(Namespace id_namespace,Date date);

}

解决方法

好的,所以我看了你的问题,这就是我所发现的。您分配给存储库接口方法参数的类型错误。

您正在寻找一个具有名称空间和服务实体具有特定ID的HistoriqueDeploiement实体的列表。请注意,命名空间和服务实体的ID是整数类型。因此,为了解决该问题,您可以按如下所示简单地重写您的方法:

def age():
    try:
        num = int(input('Please enter your birth year: '))
        if num > 2020:
            print 'Invalid input. Not a valid birth year.'
            age()
        else:
            return 2020 - num
    except ValueError:
        print 'Invalid input. Not a number.'
        age()

请注意,此处的主要更改是我们将命名空间和服务类型替换为ID的实际类型,即Integer类型