这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@azhwani
Copy link
Contributor

@azhwani azhwani commented Sep 5, 2024

  • Add two Hibernate entities: Person and Address
  • Add a test case to showcase how @mapsid helps to implement shared primary key mapping


@Test
void givenPersonEntityWithIdentifier_whenAddingAddress_thenPersistWithSameIdentifier() {
// Given person with identifier 3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the comments - code is self explained

person.setLastName("Abderrahim");
session.persist(person);

// Address without specifying the identifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the comments - code is self explained

address.setZipode(13000);
address.setPerson(person);

// When
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the comments - code is self explained

session.persist(address);
Address persistedAddress = session.find(Address.class, personId);

// Then address shares the same identifier as person
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the comments - code is self explained

@vinipx vinipx merged commit 2cd0089 into eugenp:master Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants