user1948363
user1948363

Reputation: 11

Hibernate Hql Query Selecting a property of inner object

here is the situation: I have a Class A that contains an Object B, what I want to do is to write a Select query which extracts the A object with only one property of B which is loaded

Example:

    Class A {
       private B b;
    }


    Class B {
      private String s1;
      private Strung s2;
      private String s3;
   }

I want to extract the A object, with only the B.s1 which is loaded

Upvotes: 0

Views: 1111

Answers (1)

Stefan Steinegger
Stefan Steinegger

Reputation: 64628

Something like this?

select
  a,
  b.s1
from A a join a.B b

This loads and initializes instances of A. If B is lazy loaded, it doesn't load anything about B, except of the explicitly loaded s1. If it is not lazy loaded, you probably should only load the ids, if at all.

select
  a.id,
  b.s1
from A a join a.B b

Upvotes: 1

Related Questions