我有一个@OneToOne 关系,如下所述:
@OneToOne
@JoinColumnsOrFormulas(
{
@JoinColumnOrFormula(
column = @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID", insertable = false, updatable = false)
),
@JoinColumnOrFormula(
column = @JoinColumn(name = "CONFIG_NAME", referencedColumnName = "CONFIG_NAME", insertable = false, updatable = false)
),
@JoinColumnOrFormula(
formula = @JoinFormula(value = "'PT-BT'", referencedColumnName = "LANG_ID")
)
}
)
private ConfigurationLanguage language;
该列LANG_ID
是ConfigurationLanguage
实体映射的表上的 PrimaryKey。
但是现在,我需要使用绑定参数动态传递它,而不是使用硬编码的 JoinFormula 值...
像这样的东西:
@OneToOne
@JoinColumnsOrFormulas(
{
@JoinColumnOrFormula(
column = @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID", insertable = false, updatable = false)
),
@JoinColumnOrFormula(
column = @JoinColumn(name = "CONFIG_NAME", referencedColumnName = "CONFIG_NAME", insertable = false, updatable = false)
),
@JoinColumnOrFormula(
formula = @JoinFormula(value = ":languageId", referencedColumnName = "LANG_ID")
)
}
)
private ConfigurationLanguage language;
将其传递给 JPQL 查询,如下所示:
TypedQuery<ConfigurationCompany> query = manager.createQuery("select c from ConfigurationCompany c " +
"join c.language l " +
"where c.id.customerId = :customerId " +
"and c.id.companyId = :companyId " +
"and c.id.productId = :productId " +
"and c.id.codFilial = :codFilial " +
"and (c.id.configName in :configNames or :configNamesEmpty = true)", ConfigurationCompany.class);
query.setParameter("customerId", customerId);
query.setParameter("companyId", companyId);
query.setParameter("productId", productId);
query.setParameter("codFilial", codFilial);
query.setParameter("configNames", configNames);
query.setParameter("configNamesEmpty", configNamesEmpty);
query.setParameter("languageId", "PT-BR"); //<<<< THIS PARAMETER
但它不起作用:
org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Invalid filter-parameter name format [languageId]; expecting {filter-name}.{param-name}
我错过了什么?