@ElementCollection does not store duplicates: add test and documentation

Description

The problem is that two identical embedded in an association have the same RowKey.
The RowKey is used as key in maps and when we create the map the last RowKey overrides the previous one.

Is it possible to check adding this test to EmbeddableExtraTest:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 @Test public void testPersistWithDuplicatesInEmbeddedList() throws Exception { try ( final Session session = openSession() ) { Transaction transaction = session.beginTransaction(); final String ALTERNATIVE_NUMBER = "+1-202-555-0333"; List<String> alternativePhones = Arrays.asList( ALTERNATIVE_NUMBER, ALTERNATIVE_NUMBER ); AccountWithPhone account = new AccountWithPhone( "222", "Mobile account 222" ); account.setPhoneNumber( new PhoneNumber( "+1-222-555-0111", alternativePhones ) ); session.persist( account ); transaction.commit(); session.clear(); transaction = session.beginTransaction(); AccountWithPhone loadedUser = (AccountWithPhone) session.get( AccountWithPhone.class, account.getId() ); assertThat( loadedUser ).as( "Cannot load persisted object with nested embeddables" ).isNotNull(); assertThat( loadedUser.getPhoneNumber() ).isNotNull(); assertThat( loadedUser.getPhoneNumber().getMain() ).isEqualTo( account.getPhoneNumber().getMain() ); assertThat( loadedUser.getPhoneNumber().getAlternatives() ).containsExactly( alternativePhones.toArray( new Object[alternativePhones.size()] ) ); session.delete( loadedUser ); transaction.commit(); session.clear(); transaction = session.beginTransaction(); assertThat( session.get( AccountWithPhone.class, account.getId() ) ).isNull(); transaction.commit(); } }

Environment

None

Status

Assignee

Fabio Massimo Ercoli

Reporter

Davide D'Alto

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

backportReEvaluate

None

Components

Priority

Major