entityJoin " /> entityJoin " /> entityJoin "/>

Fetch children and parents self-referencing with primitive criteria api

33 views Asked by At

I have an Entity that is self-referencing like so:

  @Column(name = "PARENT_ID")
  private Long ParentId;

When I do this:

Join<Entity, Entity> entityJoin =
    root.join(ParentId, JoinType.LEFT);

I get an error:

org.hibernate.query.SemanticException: Attribute [path.jpa.Entity#ParentId(BASIC)] is not joinable

What I'm trying to accomplish is this:

select
    *
    from
        entity o1_0 
    where
        exists(select
            1 
        from
            entity o5_0 
        where
            o5_0.PARENT_ID=o1_0.id)

I want to fetch the rows that have the PARENT_ID and also the parents. How could I acheive this?

0

There are 0 answers