ebean-orm / ebean

Ebean ORM
https://ebean.io
Apache License 2.0
1.47k stars 261 forks source link

@OrderColumn does not work with @ManyToMany properties #1700

Open rPraml opened 5 years ago

rPraml commented 5 years ago

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

rPraml commented 5 years ago

@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.

rbygrave commented 5 years ago

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.

rPraml commented 5 years ago

We currently use a separate m2m entity which 2 id columns and one order column as workaround

c-lee8 commented 4 years ago

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

rbygrave commented 4 years ago

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.

JamesWilson3 commented 3 years ago

Hi Rob, is there other workaround now? or do we still need to do 2 OneToMany relationship as stated above?

rbygrave commented 3 years ago

No, there isn't a fix for this yet and so we really only have the workaround of modelling as 2 OneToMany relationship.

vladimirfx commented 3 years ago

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?