I am trying to create a named-query
in my orm.xml
but I am not sure how it works with the collection. I have created a query in postgresql
which gives me the correct output. But I am not able to translate it to my orm.xml
.
The postgresql
query:
SELECT b.id, b.manufacturer, b.name, b.price, b.quantity, b.version, b.incentiveentity_id
from beverageentity b INNER JOIN customerorderentity_beverageentity c ON b.id = c.beverageentities_id
Group by b.id;
CustomerOrderEntity Class:
@Entity
public class CustomerOrderEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private int id;
@Version
private int version;
private Date issueDate;
private boolean existIncentive;
@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private List<BeverageEntity> beverageEntities;
}
BeverageEntity Class:
@Entity
public class BeverageEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private int id;
private String name;
private String manufacturer;
private int quantity;
private double price;
@Version
private int version;
@ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private IncentiveEntity incentiveEntity;
In my orm.xml I have written the query like this:
<named-query name="getAllOrders">
<query>SELECT b.id, b.manufacturer, b.name, b.price, b.quantity, b.version, b.incentiveEntity.id
from BeverageEntity b INNER JOIN CustomerOrderEntity.beverageEntities c ON b.id = c.id
Group by b.id
</query>
</named-query>
But after compiling I am getting this exception:
org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT b.id, b.manufacturer, b.name, b.price, b.quantity, b.version, b.incentiveEntity.id
from BeverageEntity b INNER JOIN CustomerOrderEntity.beverageEntities c ON b.id = c.id
Group by b.id
].
[123, 159] The collection-valued path 'CustomerOrderEntity.beverageEntities' cannot be resolved to a valid association field.. Please see server.log for more details.