Bi-directional many to many with link entity

Hello @blessedmaker, your mappings look fine: this is the “correct” way to map a join-table if you have additional properties in it, the default way of mapping a many-to-many association would be the @ManyToMany annotation with @JoinTable, but as I said what you’re doing is fine.

You can try making the @ManyToOne associations in MovieEmployee lazy, by adding fetch = FetchType.LAZY, which is not the default for to-ones. This should allow to prevent loading the employee as soon as the parent entity is loaded. If it is still loaded, than that might mean you have something accessing that association in your application logic.

1 Like