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

Ordering column is not maintained by Ebean with @OrderColumn on @ElementCollection #2393

Open
vladimirfx opened this issue Sep 23, 2021 · 1 comment

Comments

@vladimirfx
Copy link
Contributor

Expected behavior

When embedded collection persists column specified in @OrderColumn should be populated in order to maintain collection ordering.

Actual behavior

The column specified in @OrderColumn is not populated at all.

Steps to reproduce

Sample mapping (in Kotlin, sorry):

@Entity
class Order {
  @Id
  val id: Long = 0

  @ElementCollection
  @OrderColumn(name = "ordinal")
  val items: MutableList<OrderItem> = mutableListOf()
}

@Embeddable
data class OrderItem(
  val nomenclatureId: Long,
  val amount: Int,
  val comment: String? = null,
)

Order item schema:

create table order_item
(
	order_id bigint not null primary key,
	ordinal int not null primary key,
	nomenclature_id bigint not null,
        amount int not null,
	comment varchar(200)
);

https://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html

Specifically:

The order column must be of integral type. The persistence provider maintains a contiguous (non-sparse) ordering of the values of the order column when updating the association or element collection. The order column value for the first element is 0.

That works in any compliant JPA provider and we were hit by this on few cases in the migrated projects.

So if it is planned to implement I will provide tests. If not - may I ask for some workaround for this issue?

@rPraml
Copy link
Contributor

rPraml commented Jan 21, 2022

@rbygrave we hit the same problem now,
when defining @ElementCollections like

  @ElementCollection
  @CollectionTable(joinColumns = @JoinColumn(name = "person_id"))
  @OrderColumn(name="foo")
  List<EcPhone> phoneNumbers = new ArrayList<>();

We would expect an order by statement.
For example in TestElementCollectionEmbeddedList

 assertSql(sql.get(1)).contains("select t0.person_id, t0.country_code, t0.area, t0.phnum from ecbl_person_phone_numbers");
 assertSql(sql.get(1)).contains("order by t0.foo")

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

2 participants