Custom join without relationships

57 views
Skip to first unread message

Duong Nguyen

unread,
Oct 20, 2022, 7:54:35 AM10/20/22
to Ebean ORM
Hello Ebean ORM team,

After many hours searching and google, I cannot find how to make a custom join by io.bean.Query<T>. So, I make this conversation for helping.

Most of examples say that I could use raw sql to contains the join statements, but that is not convenient for dynamic query.

Using filterMany seem not good idea because I don't want to keep too many @ManyToMany, @OneToMany, @ManyToOne annotations on the entities only for join statements.

Therefore, I am looking for a way to make custom join similar below:

Query<Product> query = DB.find(Product.class);
query.join(Category.class, "product.categoryId = category.id", "inner");


Is it possible for me to do it with Ebean?

Cheers, Duong.



Rob Bygrave

unread,
Jan 10, 2023, 3:36:16 AM1/10/23
to Ebean ORM
> Is it possible for me to do it with Ebean?

You can do anything with a DtoQuery and writing your own SQL.

But no, we can't create an ORM query to have a join to between 2 entities without some relationship like @OneToMany or @ManyToOne etc.



> I don't want to keep too many @ManyToMany, @OneToMany, @ManyToOne annotations on the entities only for join statements.

Well these annotations have a bad reputation due to how they are used and work with other ORMs so to some extent I understand the hesitation.

However, with Ebean ORM we support partially objects and have a query language that allows us to control the "projection of the object graph".

Also the reason for Ebean ORM to exist is that it's an ORM and what that means is that it's main job is "to build object graphs" and these "object graphs" are not necessarily flat rows / tuples but instead graphs with cardinality relationships and this why  we have the OneToMany, OneToOne, ManyToOne, ManyToMany.



Apologies for only just getting to answer this question. Unfortunately I've have a bunch of emails from this google group go into my spam folder and I'm only now just finding out that a bunch of questions like this didn't get any response. 

Apologies,
Rob.
Reply all
Reply to author
Forward
0 new messages