|
I have an entity with the next filter:
@FilterDef(name="localeFilter", parameters={@ParamDef(name="locale", type="java.lang.Integer")})
And here is the property:
@ManyToOne(fetch = FetchType.EAGER)
@JoinFormula("(select idioma.idcatalogolocale from Core_Catalogo catalogo inner join core_catalogoidioma idioma on catalogo.idcatalogo = idioma.idcatalogo where idioma.ididioma = :localeFilter.locale)")
private CoreCatalogoidioma idioma;
I enable the filter with the next code:
em.unwrap(Session.class).enableFilter("localeFilter").setParameter("locale", 1);
And then I try to create the query with a CriteriaQuery and a NPE is thrown:
TypedQuery query = em.createQuery(cq);
Here is the Stacktrace:
I've debugged the code and I find the problem. At the end of the method doCompile of the org.hibernate.hql.internal.ast.QueryTranslatorImpl class the filters are set to null
this.enabledFilters = null;
In the class org.hibernate.ejb.AbstractEntityManagerImpl in the method createQuery there is the next code:
org.hibernate.Query hqlQuery = getSession().createQuery( jpaqlString );
if ( options.getValueHandlers() == null ) {
options.getResultMetadataValidator().validate(hqlQuery.getReturnTypes());
}
In this code, first the query is created but when the method getReturnTypes is invoked the NPE is thrown because the filters are set to null
If I need to do another thing to use @Filter with @JoinFormula please point me in that direction
Thanks in advance
|