Taco类中有Ingredient相关字段:
@ManyToMany(targetEntity=Ingredient.class) @Size(min=1, message="You must choose at least 1 ingredient") private List<Ingredient> ingredients;
依据Taco_Ingredients表进行连表查询:
但是问题在于hibernate在连表查询时,默认join table中的字段为taco_id和ingredient_id,这与实际join table中的column名称不符合。
@ManyToMany(targetEntity=Ingredient.class) @Size(min=1, message="You must choose at least 1 ingredient") @JoinTable(name = "Taco_Ingredients", joinColumns = @JoinColumn(name = "taco"), inverseJoinColumns = @JoinColumn(name = "ingredient")) private List<Ingredient> ingredients;
因为hibernate默认将枚举类型字段的EnumType设置为EnumType.ORDINAL
显然,从mysql中获取到的type为string类型,无法转换为序数
@Enumerated(EnumType.STRING) private final Type type;