Port of schuchert.wikispaces.com


Ejb_3_Tutorial_2_Exercises

Ejb_3_Tutorial_2_Exercises

Fetching and Lazy Initialization

The Company entity has one attribute where we’ve specified the fetch type. Review the employees attribute in Company.java. Remove the fetch = FetchType.EAGER and execute the tests.

There’s another way to make this “work” by manually reading the contents of the collection. Experiment with that and see if you can get it to work using this technique. What is the impact of ) on a lazy fetch? (Hint: you might have some issues with this combination.)

Review

Hint: You can compare the SQL from each approach by adding the following line to the persistence.xml:

         <property name="hibernate.show_sql" value="true" />

Fetch and Lazy Initialization Revisited

Add a unit test where you:

Review

Add Tests

Review the driver from the first JPA tutorial. Use that as example source from which you can derive tests.

In addition, add the following tests:

Attempt to Hire Person Already Hired

Write a test that creates a Person and 2 companies. Hire the person at the first company. Attempt to hire the person for the second company.

The results should be one of two things (you choose):

Hire Person with Same Name/Address

Create two people and hire them both. Make sure this works.

Question, do you think it should work? If not, then update the equals and hashCode method and make this test be one that only works if the attempt fails.

Test Isolation

Use the installed QuantumDB Perspective to discover if our tests are leaving around objects after they have completed. Assuming they have, write code to have each test clean up after itself.


Comments

" Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.