ebean icon indicating copy to clipboard operation
ebean copied to clipboard

@OrderColumn does not work with @ManyToMany properties

Open rPraml opened this issue 5 years ago • 8 comments

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 avatar May 10 '19 15:05 rPraml

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

rPraml avatar Jul 12 '19 16:07 rPraml

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.

rbygrave avatar Jul 16 '19 22:07 rbygrave

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

rPraml avatar Jul 17 '19 14:07 rPraml

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

c-lee8 avatar Sep 08 '20 07:09 c-lee8

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.

rbygrave avatar Sep 10 '20 21:09 rbygrave

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

JamesWilson3 avatar Aug 26 '21 09:08 JamesWilson3

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

rbygrave avatar Aug 26 '21 21:08 rbygrave

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?

vladimirfx avatar Sep 23 '21 17:09 vladimirfx