Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@OrderColumn does not work with @ManyToMany properties #1700

Open
rPraml opened this issue May 10, 2019 · 8 comments
Open

@OrderColumn does not work with @ManyToMany properties #1700

rPraml opened this issue May 10, 2019 · 8 comments

Comments

@rPraml
Copy link
Contributor

rPraml commented May 10, 2019

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
Copy link
Contributor Author

rPraml commented Jul 12, 2019

@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
Copy link
Member

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
Copy link
Contributor Author

rPraml commented Jul 17, 2019

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

@c-lee8
Copy link

c-lee8 commented Sep 8, 2020

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
Copy link
Member

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
Copy link

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

@rbygrave
Copy link
Member

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

@vladimirfx
Copy link
Contributor

Same for element collection (#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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants