小编Ser*_*nik的帖子

Spring Data JPA - 按集合中字段的名称查找

两天的思考和搜索以及任何结果 - 互联网和文档都不能回答我的问题。

我需要构造一个 Jpa 存储库方法名称以从数据库中,字段获取。我还使用连接表和实体来存储配方中每种成分的数量Set<Recipe>IngredientingrNameRecipeIngredientRecipeIngredient

请帮助。

谢谢!

我尝试做这样的事情:

package com.pck.repository;

import com.pck.Recipe;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Set;

@Repository
public interface RecipeRepository extends JpaRepository<Recipe, Integer> {

    public Set<Recipe> findAllByRecipeIngrs_Ingredient_IngrNameIn(Collection<String> ingredientNames)

}

Run Code Online (Sandbox Code Playgroud)

但这不起作用。

食谱:

package com.pck.entity;

import javax.persistence.*;
import java.util.*;

@Entity
@Table(name="recipes")
public class Recipe {

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true, mappedBy = "recipe")
    private Set<RecipeIngredient> recipeIngrs;

    public Recipe() {}

    public Set<RecipeIngredient> getRecipeIngrs() {
        return ingredients;
    } …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpql spring-data

1
推荐指数
1
解决办法
5955
查看次数

标签 统计

hibernate ×1

java ×1

jpql ×1

spring ×1

spring-data ×1