Uploaded image for project: 'Hibernate OGM'
  1. OGM-1237

@ElementCollection does not store duplicates: add test and documentation

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None

      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:

      	@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();
      		}
      	}
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: