简体   繁体   English

Spring Data JPA通过嵌入式密钥中的多个字段查找

[英]Spring data jpa find by multiple fields in embedded key

I need to find an object using two fields of an embedded key 我需要使用嵌入式密钥的两个字段来查找对象

Here is the embedded key: 这是嵌入式密钥:

public class OrderItemId implements Serializable {

    private static final long serialVersionUID = 1163347452811191867L;

    @Column(name = "order_code", length = 25)
    private String orderCode;

    @Column(name = "barcode", length = 25)
    private String barcode;

    // ....
}

Here is the class of the object I want to query: 这是我要查询的对象的类:

@Entity
@Table(name = "order_item")
public class OrderItem {

    @EmbeddedId
    @NotNull
    private OrderItemId id;

    @Column(name = "quantity")
    private Integer quantity;

    @Column(name = "price")
    private Double price;

    // ...
}

As in this StackOverflow Answer 就像在这个StackOverflow答案中一样

To query by embedded key orderCode , I can write something like this 要通过嵌入式键orderCode查询,我可以这样写

public List<OrderItem> findById_OrderCode(String orderCode);

and it works! 而且有效!

But I don't know how to query by both orderCode and barcode . 但是我不知道如何通过orderCodebarcode进行查询。 I have tried some forms of and but no use. 我尝试过的一些形式and ,但没有用。

没关系,我已经找到查询了,这是

public OrderItem findById_OrderCodeAndId_Barcode(String orderCode, String barcode);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 数据 JPA 通过嵌入 object 属性查找 - Spring Data JPA find by embedded object property JPA Multiple Embedded字段 - JPA Multiple Embedded fields JPA 带前缀的多个嵌入式字段? - JPA Multiple Embedded fields with prefix? 如何在spring data jpa的搜索框中搜索多个字段 - How to search multiple fields in a search box in spring data jpa 使用 Spring 数据实现复合(嵌入式 ID)外键关系 JPA - Implementing Composite (Embedded-ID) Foreign Key Relations using Spring Data JPA Spring data jpa 在空数据库中为具有包含外键的复合主键的实体创建错误的字段 - Spring data jpa creates wrong fields in empty database for entity with composite primary key that contains foreign key 什么是对多个字段使用findBy的Spring Data JPA方法,并对所有字段使用Containing子句 - What is the Spring Data JPA method to use findBy for multiple fields and also use Containing clause for all the fields Spring JPA-更新多个字段的最佳方法 - Spring JPA - Best way to update multiple fields Spring Data JPA 从主键作为外键的多个一对多关系 - Spring Data JPA multiple one to many relations from primary key as a foreign key Spring数据JPA规范-使用键查找所有数据以联接3个表 - Spring data JPA Specifications - Find all data using a key to join 3 tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM