public void test_N1N() {
ResetBasicData.reset();
// safety check to see if our customer we are going to use for the test has
// some contacts
Customer c = Ebean.find(Customer.class).setId(1).findUnique();
Assert.assertNotNull(c.getContacts());
Assert.assertTrue("no contacts on test customer 1", c.getContacts().size() > 0);
// start transaction so we have a "long running" persistence context
Transaction tx = Ebean.beginTransaction();
try {
List<Order> order = Ebean.find(Order.class).where(Expr.eq("customer.id", 1)).findList();
Assert.assertNotNull(order);
Assert.assertTrue(order.size() > 0);
Customer customer = order.get(0).getCustomer();
Assert.assertNotNull(customer);
Assert.assertEquals(1, customer.getId().intValue());
// this should lazily fetch the contacts
List<Contact> contacts = customer.getContacts();
Assert.assertNotNull(contacts);
Assert.assertTrue("contacts not lazily fetched", contacts.size() > 0);
} finally {
tx.commit();