[JIRA] (HSEARCH-1937) Consider offering a query based approach to @ContainedIn
by Yoann Rodière (JIRA)
Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate Search ( https://hibernate.atlassian.net/browse/HSEARCH?atlOrigin=eyJpIjoiODJiZmVh... ) / New Feature ( https://hibernate.atlassian.net/browse/HSEARCH-1937?atlOrigin=eyJpIjoiODJ... ) HSEARCH-1937 ( https://hibernate.atlassian.net/browse/HSEARCH-1937?atlOrigin=eyJpIjoiODJ... ) Consider offering a query based approach to @ContainedIn ( https://hibernate.atlassian.net/browse/HSEARCH-1937?atlOrigin=eyJpIjoiODJ... )
Change By: Yoann Rodière ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Today, people need to use create an association to go from an embedded entity B to the containing entity A and annotate it with {{@ContainedIn}}. This is necessary for us to know which instance of A contains the instance of B.
This is sometimes undesirable as the association is not necessary for the application. This is particularly true of ToMany associations.
An alternative approach would be to let the user express a query instead of materializing an association.
{code:java}@Entity
@ContainedIn("from A a where a.b.id in (:listOfIds)")
class B {
...
}
@Entity
@Indexed
class A {
@IndexedEmbedded
B b;
}{code}
-I think that's a not too complicated feature that can be done by a community member.-
Yoann: it is complicated, because the query approach makes little sense if we don't provide a way to "chunk" reindexing, i.e. a way to retrieve a batch of entities from the query, reindex them, flush and clear the session, continue to the next batch, etc. If we don't do that, this query mechanism will only make sense for associations with a small cardinality (an association with 8000 linked entities is a no-no). But such a chunked reindexing is hard (impossible?) to implement properly:
* we would ideally want it to read from the user session's cache, but never, ever write to the user sessions's cache (in particular the clear() calls should not remove entities that the user expects to be in the session).
* depending on the number of entities to reindex, the reindexing process could take a lot of time. We may want to make reindexing happen in a background process instead of the user session.
In conclusion, it's likely that such a feature only makes sense if we implement asynchronous processing of entity change events ([https://hibernate.atlassian.net/browse/HSEARCH-3280|https://hibernate.atl...]). Since integrating the two features would likely require API changes, I'd rather work on this ticket after [https://hibernate.atlassian.net/browse/HSEARCH-3280|https://hibernate.atl...] is solved.
We might want to abstract away from a query string and use an interface / implementation so that Hibernate Search working in non ORM environment can still benefit from this approach. I haven't thought much about this abstraction.
( https://hibernate.atlassian.net/browse/HSEARCH-1937#add-comment?atlOrigin... ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-1937#add-comment?atlOrigin... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:fd7c927 )
3 years
[JIRA] (HHH-16312) function with collection makes NullPointerException
by Florian Hof (JIRA)
Florian Hof ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6411c30... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGZmYjVjMDEw... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiOGZmYj... ) HHH-16312 ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiOGZmYj... ) function with collection makes NullPointerException ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiOGZmYj... )
Change By: Florian Hof ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6411c30... )
With criteria builder, I’m calling a function which has a collection as parameter. This fails with a NullPointerException when hibernate validates the types.
My code (simplified), where I define a generic “contains in array” check.
{code:java} protected <T> Predicate contains(Expression<Collection<T>> array, T value) {
return criteriaBuilder.equal(criteriaBuilder.literal(value), criteriaBuilder.function("ANY", Object.class, array));
}{code}
This My goal is to query an array-column, something like:
struture with an array-column: {{ALTER TABLE person ADD COLUMN tel_numbers VARCHAR ARRAY;}}
with Postgres specific: {{SELECT * FROM person p WHERE '+123456' = ANY(p.tel_numbers)}}
or eventually SQL-Standard: {{SELECT * FROM person p WHERE '+123456' = ANY(SELECT * FROM UNNEST(p.tel_numbers));}}
The function definition fails at {{ArgumentTypesValidator.validate:92}} with a {{NullPointerException}}:
{{final JdbcType jdbcType = getJdbcType( queryEngine, argument, indicators, javaType );}} // → null
{{jdbcType.getDefaultSqlTypeCode()}} → NullPointerException
The {{ArgumentTypesValidator.getJdbcType:139}} calls {{javaType.getRecommendedJdbcType}} and {{CollectionJavaType.getRecommendedJdbcType}} always returns {{null}}. I think that {{ArgumentTypesValidator.validate}} should handle a {{null}} jdbcType properly, in that case not doing the validation.
Or what is your opinion? Is there a workaround?
( https://hibernate.atlassian.net/browse/HHH-16312#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16312#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:fd7c927 )
3 years
[JIRA] (HHH-16312) function with collection makes NullPointerException
by Florian Hof (JIRA)
Florian Hof ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6411c30... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMThmZDlhODM5... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiMThmZD... ) HHH-16312 ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiMThmZD... ) function with collection makes NullPointerException ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiMThmZD... )
Change By: Florian Hof ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6411c30... )
With criteria builder, I’m calling a function which has a collection as parameter. This fails with a NullPointerException when hibernate validates the types.
My code (simplified), where I define a generic “contains in array” check.
{ noformat code:java } protected <T> Predicate contains(Expression<Collection<T>> array, Expression< T > value) {
return criteriaBuilder.equal( criteriaBuilder.literal( value ) , criteriaBuilder.function("ANY", Object.class, array));
}{ noformat code }
This fails at {{ArgumentTypesValidator.validate:92}} with a {{NullPointerException}}:
{{final JdbcType jdbcType = getJdbcType( queryEngine, argument, indicators, javaType );}} // → null
{{jdbcType.getDefaultSqlTypeCode()}} → NullPointerException
The {{ArgumentTypesValidator.getJdbcType:139}} calls {{javaType.getRecommendedJdbcType}} and {{CollectionJavaType.getRecommendedJdbcType}} always returns {{null}}. I think that {{ArgumentTypesValidator.validate}} should handle a {{null}} jdbcType properly, in that case not doing the validation.
Or what is your opinion? Is there a workaround?
( https://hibernate.atlassian.net/browse/HHH-16312#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16312#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:fd7c927 )
3 years
[JIRA] (HHH-16312) function with collection makes NullPointerException
by Florian Hof (JIRA)
Florian Hof ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6411c30... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiM2NlNGExYmJm... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiM2NlNG... ) HHH-16312 ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiM2NlNG... ) function with collection makes NullPointerException ( https://hibernate.atlassian.net/browse/HHH-16312?atlOrigin=eyJpIjoiM2NlNG... )
Issue Type: Bug Affects Versions: 6.1.7 Assignee: Unassigned Components: query-criteria Created: 15/Mar/2023 06:26 AM Priority: Major Reporter: Florian Hof ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=6411c30... )
With criteria builder, I’m calling a function which has a collection as parameter. This fails with a NullPointerException when hibernate validates the types.
My code (simplified), where I define a generic “contains in array” check.
protected <T> Predicate contains(Expression<Collection<T>> array, Expression<T> value) {
return criteriaBuilder.equal(value, criteriaBuilder.function("ANY", Object.class, array));
}
This fails at ArgumentTypesValidator.validate:92 with a NullPointerException :
final JdbcType jdbcType = getJdbcType( queryEngine, argument, indicators, javaType ); // → null
jdbcType.getDefaultSqlTypeCode() → NullPointerException
The ArgumentTypesValidator.getJdbcType:139 calls javaType.getRecommendedJdbcType and CollectionJavaType.getRecommendedJdbcType always returns null. I think that ArgumentTypesValidator.validate should handle a null jdbcType properly, in that case not doing the validation.
Or what is your opinion? Is there a workaround?
( https://hibernate.atlassian.net/browse/HHH-16312#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16312#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:fd7c927 )
3 years