0

I have following entity:

@Entity
class A {
   @Id
   @GeneratedValue(generator = "system-uuid")
   @GenericGenerator(name = "system-uuid", strategy = "uuid2")
   String id;
        //some field        

   @ManyToMany
   Set<B> other;
}

@Entity
class B {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    String id;
    //some field
}

I would like to create hql query which list ids of B for A entity contained in Set<B>.

Somethig like (incorrect):

select a.other.id from A as a where a.id = :pid
RMachnik
  • 3,598
  • 1
  • 34
  • 51
user902691
  • 1,149
  • 4
  • 20
  • 46
  • What's the exception thrown and how are you calling it from hibernate. See also http://stackoverflow.com/questions/11807698/how-to-retrieve-only-certain-fields-of-an-entity-in-jpql-or-hql-what-is-the-equ – Adam Gent May 14 '14 at 12:14

1 Answers1

0

Try something like this :

select a.other.id from A a join a.other o where a.id = :pid
Snorky35
  • 426
  • 6
  • 15
  • 1
    Have you tried it? I'm not sure but I *think* you ought to use the alias in the projection (so `select o.id ...`). – mabi May 14 '14 at 09:01
  • No did not test it, it was something i thought i remembered about, sorry. – Snorky35 May 14 '14 at 13:30