Get all updates of Java4s
Newsletter

Part 3 HQL, Different Ways Of Executing HQL Commands

We can execute our HQL command in 3 ways,  like by selecting total object, partial object (more than one column), partial object (with single column).  Let us see..

 

Different Ways Of Executing HQL

Case 1: [ Selecting Complete Object ]

  • In this approach, we are going to select complete object from the database, so while iterating the collection, we need to typecast each object into our  POJO class type only
  • Internally hibernate converts each row selected from the table into an object of POJO class and hibernate stores all these POJO class objects into list so while iterating the collection, we typecast into POJO class type

Example:


Case 2: [ Selecting Partial Object ]

  • In this approach we are going to select partial object, (selected columns, i mean more than one column not single column)
  • In this case hibernate internally stores the multiple column values of each row into an object array and stores these object arrays into List collection
  • At the time of iterating the collection, we need to typecast the result into an object arrays

Example:

Case 3: [ Selecting Partial Object ]

  • In this case we are going to select partial object with single column from the database
  • In this case hibernate internally creates an object of that value type and stores all these objects into the list collection
  • At the time of iterating the collection, we need to typecast into that object type only

Example:

Note:  it.next() return type is always Object

 

 

Next Session HQL part 4

You Might Also Like

Comments

6 Responses to “Part 3 HQL, Different Ways Of Executing HQL Commands”
  1. Alen says:

    It can’t be simpler than this. Great job buddy.

  2. Govind says:

    Awesome site. Really, learned in depth even though i worked these technologies. Simple explanation, motivates for java developer to learn.

  3. Ram says:

    Good work Siva.!!

  4. Nagarjuna says:

    Great tutorial….

    in Example one Project p = (Product)o .
    i think its a Product p = (Product)o

  5. Poornima says:

    Hi sir I could understand all the concepts very well. Thank you so much for this tutorials. It is very helpful and great explanation. I am lucky I saw this tutorials. very nice.

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Spring-Boot-tutorials Hibernate tutorials Spring tutorials Struts tutorials Servlets tutorials Ajax tutorials Log4j tutorials jQuery tutorials Json tutorials Core Java tutorials Web Services tutorials AngularJs tutorials
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2017 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.