What type of object is returned when a sleeping request is connected

When I have the request below, he will give me a list of products.

List<Product>=

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

What will he return when there is a connection, as shown below.

getCurrentSession().createQuery("SELECT p FROM Product p inner join ProductCategory pc where p.id=pc.id").list();
+5
source share
5 answers

SELECT p FROM Product p inner join ...something like this gives you a list of Products.

FROM Product p inner join ... something like this gives you a list of arrays.

+3
source

As a result, he must return List<Object[]>. Check out this thread

And you have to access your objects, for example

for (Object[]> result : query.list()) {
    Product p = (Product) result[0];
    ProductCategory pc = (ProductCategory) result[1];
}
+2
source

list . Product

List list = session.createQuery("SELECT p FROM Product p inner 
                      join ProductCategory pc where p.id=pc.id").list();
+1

According to the documentation for javax.persistence.Query you will get a list. Why do you think this should be different?

0
source

This class, dropped from the java.lang.object class to the model, does not work in any way. Below is my code.

List<Contactinfo> listStudentInfo = new ArrayList<Contactinfo>();                    
                         //listStudentInfo = dataService.getAllStudent(studentInfo);
                         listStudentInfo = dataService.getStudentInfo();
                         System.out.println(listStudentInfo.size()); 
                         Contactinfo contactinfo = (Contactinfo)listStudentInfo.get(0);

But in sleep mode, you don’t need to join if you have both Entity associated with @ Many-to-one and the One-on-One annotation. Then you need to select only one object, you will automatically get access to another object through the connection. Make sure you use the getter (), setter () method for the connection field. Hope this clarifies the situation.

0
source

All Articles