ebean
ebean copied to clipboard
@OrderColumn does not work with @ManyToMany properties
Actual behavior
@OrderColumn is ignored on ManyToMany lists. According to the documentation, this should be supported:
The OrderColumn annotation is specified on a OneToMany or ManyToMany relationship or on an element collection.
Expected behavior
Defining @OrderColumn on a M2M property like this
public class MtmChild {
@OrderColumn(name = "masters_order")
@ManyToMany
List<MtmMaster> masters;
should result in an additional column in the DDL script. (and of course, Ebean should maintain that order column like it is done in OneToMany, see TestOrderedList)
Steps to reproduce
Add the above annotation in misc.migration.v1_1.MtmChild and run the DbMigrationGenerateTest
The generated DDLs do not contain information about an order-column
@rbygrave can you take a look at this issue and maybe give an estimation if you have time to fix that or give me some tips how I should try to fix it.
Hi @rPraml . Can you let me know the impact of this on your project? I'm guessing we haven't got a good workaround for this and it's a problem? I'm thinking you'll maybe looked to map the intersection table explicitly and not using @ManyToMany
... and then having to update the order column value in code?
There are a bunch of things I have on the TODO list which I am hoping/wondering if I can look at first basically but I get the feeling we need to give this some attention.
We currently use a separate m2m entity which 2 id columns and one order column as workaround
Hi, is there any progress or work around on this issue?
I notice that the list fetched by ebean seems to ignore the OrderColumn annotation entirely?
Thank you
any progress
No, sorry. This had a workaround so other things (performance monitoring in particular) have taken precedence.
work around on this issue?
The workaround to date is to model as 2 OneToMany (so model the intersection/bridge explicitly).
I notice that the list fetched by ebean seems to ignore the OrderColumn annotation entirely?
Yes.
Cheers, Rob.
Hi Rob, is there other workaround now? or do we still need to do 2 OneToMany relationship as stated above?
No, there isn't a fix for this yet and so we really only have the workaround of modelling as 2 OneToMany relationship.
Same for element collection (https://github.com/ebean-orm/ebean/issues/2393) but for that case we can't define PK on the table which is lead to poor database consistency... Also, no workaround for element collection exists.
Any chance to support @OrderColumn
?