Session s = openSession();
Transaction t = s.beginTransaction();
Customer cust = new FavoriteCustomer("JBoss", "RouteOne", "Detroit");
s.persist(cust);
t.commit();
s.close();
s = openSession();
CustomerId custId = new CustomerId("JBoss", "RouteOne");
t = s.beginTransaction();
cust = (Customer) s.get(Customer.class, custId);
assertEquals( "Detroit", cust.getAddress() );
assertEquals( cust.getCustomerName(), custId.getCustomerName() );
assertEquals( cust.getOrgName(), custId.getOrgName() );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
cust = (Customer) s.createQuery("from Customer where id.customerName = 'RouteOne'").uniqueResult();
assertEquals( "Detroit", cust.getAddress() );
assertEquals( cust.getCustomerName(), custId.getCustomerName() );
assertEquals( cust.getOrgName(), custId.getOrgName() );
t.commit();
s.close();
s = openSession();
t = s.beginTransaction();
cust = (Customer) s.createQuery("from Customer where customerName = 'RouteOne'").uniqueResult();
assertEquals( "Detroit", cust.getAddress() );
assertEquals( cust.getCustomerName(), custId.getCustomerName() );
assertEquals( cust.getOrgName(), custId.getOrgName() );
s.createQuery( "delete from Customer" ).executeUpdate();
t.commit();
s.close();