2

I have this 1-N case

class BaseEntity {

  @Id
  Long id;

  String name;
}

class RelId {

  @Column(name = "BU_ID", nullable = false, insertable = true, updatable = true)
  private Long buId;

  @Column(name = "ID", nullable = false, insertable = true, updatable = true)
  private Long id;
}

class ExtA {

  @EmbeddedId
  private RelId id;

  @ManyToOne(optional = false, fetch = FetchType.LAZY)
  @JoinColumn(name = "ID", insertable = false, updatable = false)
  private BaseEntity baseEntity;
}

class ExtB {

  @EmbeddedId
  private RelId id;

  @ManyToOne(optional = false, fetch = FetchType.LAZY)
  @JoinColumn(name = "ID", insertable = false, updatable = false)
  private BaseEntity baseEntity;
}

class BaseEntityEx {

  BaseEntity baseEntity;
  ExtA extA;
  ExtB extB;
}

Now I would like to select the BaseEntityEx where the buId is equals to 2 with a query like this

@Query(value = "SELECT NEW BaseEntityEx(b, ea, eb)
      + " FROM BaseEntity b "
      + " LEFT JOIN ExtA ea ON (ea.id.id=b.id AND ea.id.buId=:buId)"
      + " LEFT JOIN ExtB eb ON (eb.id.id=b.id AND eb.id.buId=:buId)"
      + " WHERE"
      + "   b.id=:id")
public BaseEntityEx getBaseEntityExByRelId(@Param("buId") long buId, @Param("id") long id);

But it does not work. How can I do that?

P.S. I would like to keep the relation only on ExtA and ExtB because when I use BaseEntity I don't want to load lazily or not hundreds of relations.

The error that I obtain is:

antlr.SemanticException: Path expected for join!
dash1e
  • 7,677
  • 1
  • 30
  • 35

0 Answers0