Hibernate: exception when using the built-in HQL query

I have a customer shopping app. These customers have a cart containing products. Here's a (simplified) display using inline boxes:

@Entity class Customer { @Embedded private Cart cart; // Constructors, setters, equals... omitted } @Embeddable class Cart { @ElementCollection @JoinTable(name = ...) private Set<Product> products = new HashSet<>(); ... } @Embeddable class Product { private String name; ... } 

Now I am trying to get a basket with HQL. I know that I cannot directly request file attachments, but nothing prevents me from choosing it as a field:

 select c.cart from Customer c where c.id = 1 

but this leads to the following exception:

 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at org.hibernate.hql.ast.util.ColumnHelper.generateScalarColumns(ColumnHelper.java:62) at org.hibernate.hql.ast.tree.DotNode.setScalarColumnText(DotNode.java:661) at org.hibernate.hql.ast.tree.SelectClause.renderScalarSelects(SelectClause.java:359) ... 

I could overcome this problem by simply retrieving the client and going through its getCart () method, but I am wondering if this problem was caused by an incorrect display or something similar. Thank you very much!

+4
source share

Source: https://habr.com/ru/post/1445630/


All Articles