Can't get ManyToMany to work, receive internal NPE

45 views
Skip to first unread message

Tuxgamer 32

unread,
Feb 20, 2024, 1:56:44 PMFeb 20
to Ebean ORM
Hi Rob,

I got two entity classes, users and tenants. There are three database tables (two with the same name), plus users_tenants, which has user_id and tenant_id. Both columns are foreign keys to the respective tables primary keys.

From how I understood, in both entities, I will need to add a List to the other one, along with @ManyToMany annotations. One side also requires @JoinTable.

However, I am receiving a NullPointerException deep from within io.ebeaninternal. Please find the example repository here:

Important bits:

I am running on Java temurin-21.0.2 with a PostgreSQL database and HikariCP connection pool. All other relationships in this project work perfectly fine (OneToMany, ManyToOne).

What am I doing wrong? The documentation page for ManyToMany unfortunately shows up empty for me, so I've been operating off of random internet posts.

Thank you very much in advance,
Georg / Tux

Rob Bygrave

unread,
Feb 22, 2024, 3:22:07 AMFeb 22
to Ebean ORM
The problem here is that the UserEntity does not have a @Id property. If we add a @Id to https://github.com/TuxGamer/ebean-example/blob/main/src/main/java/org/example/ebean/entities/UserEntity.java#L15 it will work.

Ebean technically allows us to model entities without an @Id property, but in this case it is not detecting that this isn't valid for this case with the ManyToMany and is giving us an unhelpful error.

Cheers, Rob.  

Tuxgamer 32

unread,
Feb 23, 2024, 9:21:41 AMFeb 23
to Ebean ORM
Thank you so much - not sure how I missed this. It works perfectly now :D
Reply all
Reply to author
Forward
0 new messages