JPA @JoinFormula with BindParameter

1.4k views Asked by At

I have a @OneToOne relationship described as below:

@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;

The column LANG_IDis PrimaryKey on the table mapped by the ConfigurationLanguageentity.

But now, instead of using the JoinFormula value as hardcoded, I need to pass it dynamically, using a bind parameter...

Something like this:

@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;

Passing it to the JPQL Query as bellow:

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

But it's not working:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: Invalid filter-parameter name format [languageId]; expecting {filter-name}.{param-name}

What Am I missing?

0

There are 0 answers