}
@Test
public void canUseObjectIdAssignedUponInsertInAssociation() {
OgmSession session = openSession();
Transaction tx = session.beginTransaction();
// given
MusicGenre classicRock = new MusicGenre( "Classic Rock" );
Bar goldFishBar = new Bar( "Goldfisch Bar" );
goldFishBar.setMusicGenre( classicRock );
classicRock.getPlayedIn().add( goldFishBar );
Bar sharkStation = new Bar( "Shark Station" );
sharkStation.setMusicGenre( classicRock );
classicRock.getPlayedIn().add( sharkStation );
// when
session.persist( classicRock );
session.persist( goldFishBar );
session.persist( sharkStation );
tx.commit();
session.clear();
tx = session.beginTransaction();
// then
Bar barLoaded = (Bar) session.load( Bar.class, goldFishBar.getId() );
assertThat( barLoaded.getName() ).isEqualTo( "Goldfisch Bar" );
assertThat( barLoaded.getMusicGenre() ).isNotNull();
assertThat( barLoaded.getMusicGenre().getName() ).isEqualTo( "Classic Rock" );
tx.commit();
session.clear();
tx = session.beginTransaction();
MusicGenre genreLoaded = (MusicGenre) session.load( MusicGenre.class, goldFishBar.getMusicGenre().getId() );
assertThat( genreLoaded.getPlayedIn() ).onProperty( "name" ).containsOnly( "Goldfisch Bar", "Shark Station" );
tx.commit();
session.close();
}