Bug (?) @OrderColumn(name = "index") didnt add a index in column in database

152 views
Skip to first unread message

Вадим Панов

unread,
Jun 4, 2021, 4:02:01 PM6/4/21
to Ebean ORM
Hi, have some problem with this annotation @OrderColumn
I have
@Entity
class PromiseEntity(
@Id override val id: UUID,
initialData:  Promise?
) {
@ElementCollection
@CollectionTable(name = "resultod")
@OrderColumn(name = "index")
private var resultOds: List< ResultOd  > = emptyList()
}

and yaml changelog

- changeSet:
id: create_promise
author: test
changes:
- createTable:
tableName:  promise
columns:
- column:
name:  promise_id
type: UUID
constraints:
nullable: false
- column:
name: index
type: smallint
- column:
name: percent_to_go
type: VARCHAR(200)
- column:
name: penalty_to_go
type: VARCHAR(200)
- createIndex:
tableName:  promise
indexName: ix_ promise_id
columns:
- column:
name:  promise_id

but in fact it didnt add index in column

Rob Bygrave

unread,
Jun 5, 2021, 11:25:51 PM6/5/21
to ebean@googlegroups
and yaml changelog

Ebean does not produce yaml format changeLog so it is not clear where this comes from.

The change log does not seem to match the model given. There isn't a resultod table?

Regardless, why do you expect an index to be automatically be created for the order column?  I guess the question is how to define an index on an element collection table.

Cheers, Rob.



--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/90c8bbbd-159b-4bd6-8d4e-24607c00bc6fn%40googlegroups.com.

Вадим Панов

unread,
Jun 6, 2021, 10:31:38 AM6/6/21
to eb...@googlegroups.com
Perhaps i explained incorrectly, table I am creating using yaml
Sorry for incorrect changelog  this is correct, i used for resultOd table this @OrderColumn and i thought taht when using it and specifying a column inside the annotation, it will write values inside it to this table
- changeSet:
id: create_result_od

author: test
changes:
- createTable:
          tableName: result_od

columns:
- column:
name: promise_id
type: UUID
constraints:
nullable: false
- column:
name: index
type: smallint
- column:
                name: sum_to_go
type: VARCHAR(200)
- column:
name: od_to_go
type: VARCHAR(200)
- createIndex:
tableName: result_od
indexName: ix_promise_id
columns:
- column:
name: pomise_id

вс, 6 июн. 2021 г. в 06:25, Rob Bygrave <robin....@gmail.com>:
You received this message because you are subscribed to a topic in the Google Groups "Ebean ORM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ebean/FqGYG9UnavQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ebean+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ebean/CAC%3Dts-EjYKo78DzEM3mXpBjHa_RRPL2Xsaogi5Pyh0GKSZieeg%40mail.gmail.com.

Rob Bygrave

unread,
Jun 8, 2021, 12:54:12 AM6/8/21
to ebean@googlegroups
> @OrderColumn(name = "index")

Specifying the above @OrderColumn does not imply a database index should be created. If we want an index in this case we need to explicitly specify it via either:


- Ebeans' extra-ddl - https://ebean.io/docs/extra-ddl/


Noting that no Ebean tooling generates migrations in yaml format so it isn't clear what tooling is being used here to produce the yaml output. Ultimately we need to explicitly define the database index though and the 2 above options are the ways we do this with Ebean generating the DDL.

Cheers, Rob.


Владимир Коньков

unread,
Jun 18, 2021, 6:27:09 AM6/18/21
to Ebean ORM
As I understand the original question is not about database index but about the insertion of List index value in the column specified by @OrderColumn. In other words - Ebean to not insert the List index value in the column specified by @OrderColumn but it should according to comply with JPA 2+. (https://www.logicbig.com/tutorials/java-ee-tutorial/jpa/order-column.html)

As result:
 - no order is preserved in List
 - user cant create a unique database index for such table (in the example below, the unique index for (promise_id, index) is not possible because of index column is null)

In addition - Ebean can use pair of FK + Ordinal columns (because it is uniquee) to update certain rows in the target table instead of deleting and inserting all rows in case of collection modification. Usually, it is far more efficient because it is a rare situation when the whole collection is changed. This optimization is implemented in Eclipselink and Datanucleus, not sure about Hibernate.

I've hit by this issue too and forced to work around this by using default value from database sequence for such ordinal column. It solved the first problem (insertion order is preserved) but not solved the second.

I can provide PR with the test for that issue.
вторник, 8 июня 2021 г. в 07:54:12 UTC+3, Rob Bygrave:
Reply all
Reply to author
Forward
0 new messages