Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isCollectionType returns false for ListArrayType #377

Open
hsinyin opened this issue Dec 17, 2021 · 4 comments
Open

isCollectionType returns false for ListArrayType #377

hsinyin opened this issue Dec 17, 2021 · 4 comments

Comments

@hsinyin
Copy link

hsinyin commented Dec 17, 2021

ListArrayType is a grant child of AbstractStandardBasicType which sets isCollectionType to false.

The impact is
When using CriteriaBuilder with the field it checks if attributeMetadata.isPlural() by reading isCollectionType.
The field should be ListAttribute but since it is not a collection type it was builded as a SingularAttribute.

And calling CriteriaBuilder.isMember() throws
unknown collection expression type [org.hibernate.query.criteria.internal.path.SingularAttributePath]

Code example:

A Entity

@TypeDef(name = "list-array", typeClass = ListArrayType.class)
public class AEntity implements Serializable {
  ID and other fields..

  @Type(type = "list-array")
  @Column(name = "version", columnDefinition = "integer[]", nullable = false)
  private List<Integer> version;
}

Queries

final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<AEntity> cq = cb.createQuery(AEntity.class);
final Root<AEntity> root = cq.from(AEntity.class);

cq.select(root).where(cb.isMember(filter.getVersion(0), root.get("version")));
entityManager.createQuery(cq).getResultList();
@vladmihalcea
Copy link
Owner

vladmihalcea commented Dec 17, 2021

Hibernate Types doesn't generate the Metamodel. Hibernate does that. So, this issue is a Hibernate problem.

Therefore, you need to open thr issue on the Hibernate project and provide a fix there.

@hsinyin
Copy link
Author

hsinyin commented Dec 17, 2021

ListArrayType should overwrite isCollectionType to true. Or extend a different class like CollectionType instead.

@vladmihalcea vladmihalcea reopened this Dec 17, 2021
@vladmihalcea
Copy link
Owner

Send me a Pull Request with this fix plus a replicating test case and I'll check it out.

@nmandrescu
Copy link

For anyone facing this, a temporary workaround can be to integrated a direct DB function.

Example with above use case, on PostgreSQL:
cb.isNotNull(cb.function("array_position", Integer.class, filter.getVersion(0), root.get("version")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants