Repository navigation
Description
Describe the bug
The Map storage interface defines attributes to be multi-valued and the values should be ordered:
public interface EntityWithAttributes {
Map<String, List<String>> getAttributes();
/* ... */
}
The JPA Map implementation stores the attributes as a Set in JpaClientEntity and JpaRoleEntity. This is not preserving the order of attributes.
Version
17.0.0-SNAPSHOT
Expected behavior
- Multi-valued attribute values should be ordered when stored and retrieved from Map JPA storage.
- Multiple entries of the same value (that are equal()) should be possible
Actual behavior
- Order of Multi-valued attribute values is not preserved
- Multiple entries of the same value (that are equal()) are reduced to a single value
How to Reproduce?
It the characteristics of a Set vs. List that are described above.
The API for multi-valued attributes is currently not exposed for Clients, only for Roles.
Anything else?
There is a GitHub discussion here: #9638
The client_attribute and role_attribute table would need to have an additional column that preserves the ordering of the values, for example via @OrderColumn(name = "index_id").
See https://vladmihalcea.com/how-to-optimize-unidirectional-collections-with-jpa-and-hibernate/ for examples.
This column should have a unique deferrable constraint to avoid DB inconsistencies. It would need to be deferrable to allow Hibernate a re-ordering of the IDs during a transaction.
Note:
If all attributes are stored as one ordered list, changing an attribute by removing it from the list and adding it at the end would change the position of all list items in between, therefore issuing an update on all other attributes in between. An in-place update of especially single-valued attributes in the list would be preferred.
This approach would only be viable if the number of entries in the attributes table is relatively small and the order / position of list items wouldn't change so often.
Metadata
Metadata
Labels
Type
Fields
Projects
- StatusShow more project fields✅ Done
Activity
ahus1 commentedon Jan 24, 2022
@vramik noticed that the current JPA implementation doesn't support ordering of multi-valued attributes.
For example: RoleModel already support multi-valued attributes. RoleEntity contains a List of attributes but no order column. Therefore, it would allow multiple values that are equal per key, but it wouldn't support the order of the attributes.
Therefore, the current implementation is that of a bag (or idbag to be more specific). Hibernate support bags; as Java doesn't have a bag collection type, the correct Java type is still a List.
Until this has been clarified, this issue is on hold. There will be soon a new GitHub discussion on this.
ahus1 commentedon Jan 26, 2022
The discussion is now available: #9794
hmlnarik commentedon Feb 16, 2022
Rejecting this issue as per #9794 there seems no interest in getting the attributes in the right order, and there will be change in the method signatures in this respect