Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the object type returning in a join of a hibernate query

Tags:

java

hibernate

When I have the below query it will give me a list of Product.

List<Product>=

getCurrentSession().createQuery("SELECT p FROM Product p ").list();

What will it return when there is a join as below.

getCurrentSession().createQuery("SELECT p FROM Product p inner join ProductCategory pc where p.id=pc.id").list();
like image 353
Sanjaya Liyanage Avatar asked May 02 '13 05:05

Sanjaya Liyanage


1 Answers

It should return List<Object[]> as a result. Please see this thread

And you should access your entities like

for (Object[]> result : query.list()) {
    Product p = (Product) result[0];
    ProductCategory pc = (ProductCategory) result[1];
}
like image 186
sanbhat Avatar answered Oct 05 '22 13:10

sanbhat