Note:
There is already a test for this issue in the code base:
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:
{code} @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(); } } {code} |
|