java - JPA TypedQuery 不返回给定条件的结果
问题描述
我有以下型号:
@Entity
@Table(name = "product")
public class Product implements Serializable {
@Id
@GeneratedValue(generator = "product_id_seq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "product_id_seq", sequenceName = "product_id_seq", allocationSize = 1)
@Column(name = "id")
private Long id;
@OneToMany(mappedBy = "product")
private List<ProductContent> productContent;
@Column(name = "expired_at", nullable = false)
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date expiredAt;
@Column(name = "created_at", nullable = false)
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date createdAt;
@Entity
@Table(name = "product_content")
public class ProductContent {
@Id
@GeneratedValue(generator = "product_content_id_seq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "product_content_id_seq", sequenceName = "product_content_id_seq", allocationSize = 1)
@Column(name = "id")
private Long id;
@Column(name = "title", nullable = false)
private String title;
@Column(name = "content", columnDefinition="TEXT", nullable = false)
private String content;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "product_id")
private Product product;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "supported_locale_id")
private SupportedLocale locale;
@Entity
@Table(name = "supported_locale")
public class SupportedLocale {
@Id
@GeneratedValue(generator = "supported_locale_id_seq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "supported_locale_id_seq", sequenceName = "supported_locale_id_seq", allocationSize = 1)
@Column(name = "id")
private Long id;
@Column(name = "language_name", nullable = false)
private String languageName;
@Column(name = "language_tag", nullable = false)
private String languageTag;
@OneToMany(mappedBy = "locale")
private List<ProductContent> productContent;
我想用英语获取所有产品。我正在使用以下类型的查询:
List<Product> products = em.createQuery("SELECT p FROM Product p JOIN p.productContent pc JOIN pc.locale l WHERE l.languageName=:languageName", Product.class)
.setParameter("languageName", "English")
.getResultList();
它返回给我的产品列表不限于英语(例如,有西班牙语 productContent)。我还尝试直接在数据库(Postgres)上使用生成的 SQL 查询,它工作正常(它只返回英语产品)。我该如何解决?
解决方案
推荐阅读
- azure-active-directory - 在 AzureAD - 应用注册中处理客户端密码到期的推荐方法是什么?
- tailwind-css - 修复了容器中带有固定导航栏的可滚动侧边栏 - Tailwind CSS
- intellij-idea - 找不到调试器路径
- django - django cbv 不发送邮件
- javascript - 使用 Qualtrics API 从矩阵表中获取列选择值
- excel - vba 更改事件
- r - 在数组内的矩阵上更改名称失败
- python - 为倒计时跳过数字定义一个函数
- python - ImportError:无法导入名称'upath'django 3
- reactjs - 反应尝试使用文本输入,但没有出现