Created
July 7, 2016 14:48
-
-
Save cosbor11/db1023e71eab8e82beb0bbef82fbc32a to your computer and use it in GitHub Desktop.
Verify you can associate multiple payments after updating the data model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final Invoice myLatestInvoice = (Invoice)persistenceManager.findById(Invoice.class, 1l); | |
// This used to be a single entity and now it is a list of payments since the relationship has changed from a One To One | |
// to a One To Many. This is also handled by the light weight migration. | |
List<Payment> paymentList = myLatestInvoice.getPayments(); | |
// What previously was a one to one relationship should have the existing record in the set. | |
assert paymentList.size() == 1; | |
assert paymentList.get(0).getPaymentId() == 1; | |
// Lets add another payment to ensure we can have a ToMany Relationship | |
final Payment mySecondPayment = new Payment(); | |
mySecondPayment.setAmount(10.01); | |
mySecondPayment.setNotes("Getting a start on next months bill since I don't have enough money because I am too busy writing open source software and not focusing on my day job."); | |
mySecondPayment.setInvoice(myLatestInvoice); | |
// Persist the Payment | |
persistenceManager.saveEntity(mySecondPayment); | |
// Refresh the collection and ensure there are 2 items | |
persistenceManager.initialize(myLatestInvoice, "payments"); | |
assert paymentList.size() == 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment