public void createTables(DatabaseSession session) { SchemaManager schemaManager = new SchemaManager(session); // Start Build fieldTypes schemaManager.buildFieldTypes(Dist_Employee.tableDefinition()); schemaManager.buildFieldTypes(Company.tableDefinition()); schemaManager.buildFieldTypes(Item.tableDefinition()); // end build fieldTypes // start drop constraints try { schemaManager.dropConstraints(Dist_Employee.tableDefinition()); schemaManager.dropConstraints(Company.tableDefinition()); schemaManager.dropConstraints(Item.tableDefinition()); } catch (org.eclipse.persistence.exceptions.DatabaseException dbE) { // ignore } // end drop constraints // start replace tables schemaManager.replaceObject(Dist_Employee.tableDefinition()); schemaManager.replaceObject(Company.tableDefinition()); schemaManager.replaceObject(Item.tableDefinition()); // end replace tables // start create constraints schemaManager.createConstraints(Dist_Employee.tableDefinition()); schemaManager.createConstraints(Company.tableDefinition()); schemaManager.createConstraints(Item.tableDefinition()); // end create constraints schemaManager.createSequences(); }
public void die() { for (Company x : _stocks.keySet()) { for (int i = 0; i < _stocks.get(x); i++) { x.gain(); } } }
public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Company com = new Company(); com.setName(""); com.getName(); // simple BeanUtils.setProperty(com, "name", "Jack"); BeanUtils.getProperty(com, "name"); // indexed BeanUtils.setProperty(com, "product[1]", "NOTES SERVER"); BeanUtils.getProperty(com, "product[1]"); // mapped HashMap am = new HashMap(); am.put("1", "10010"); am.put("2", "10010"); BeanUtils.setProperty(com, "telephone", am); BeanUtils.getProperty(com, "telephone(2)"); // combined BeanUtils.getProperty(com, "employee[1].name"); // copyProperty Company com2 = new Company(); BeanUtils.copyProperties(com2, com); // converter BeanUtils.setProperty(com, "date", new Date()); BeanUtils.setProperty(com, "date", "2013-10-01"); ConvertUtils.register( new Converter() { public <T> T convert(Class<T> type, Object value) { // TODO Auto-generated method stub return null; } }, Date.class); // DynamicBean LazyDynaMap dynaBean = new LazyDynaMap(); dynaBean.set("foo", "bar"); dynaBean.set("customer", "title", "Rose"); dynaBean.set("address", 0, "address1"); System.out.println(dynaBean.get("address", 0)); Map map = dynaBean.getMap(); System.out.println(map.toString()); // returnNull dynaBean.setReturnNull(true); // Restricted dynaBean.setRestricted(true); }
// find list of all the companies with risk < comfidence. public void changeStockVal() { double old = _stockVal; _stockVal = 0; for (Company x : _stocks.keySet()) { _stockVal += x.getPrice() * _stocks.get(x); } _stockValChanged = _stockVal - old; }
protected void onNew(Event event) { Shell shell = (Shell) XWT.findElementByName(event.widget, "Root"); Company company = (Company) XWT.getDataContext(shell); Person person = new Person(); person.setName("New Manager1"); person.getAddress().setCity("ShenZhen"); company.setManager(person); }
public static void main(String[] args) { Company cmp = new MethodHidingAndOverriding(); // if we can override static, this should call method from Child class cmp.staticMethod(); // Eclipse should show warning: The static method // staticMethod() from the type Company should be // accessed in a static way // here this is called method hiding cmp.nonStaticMethod(); // here method overriding }
// global authentication method. depends on the ClientType public CouponClientFacade login(String name, String password, ClientType clientType) { Utils.logMessage(this, Severity.DEBUG, clientType + " login invoked with pass = "******"db hash = " + _adminHash); Utils.logMessage(this, Severity.DEBUG, "calculated hash = " + md5HashOfPassword); if (md5HashOfPassword.equals(_adminHash)) { Utils.logMessage(this, Severity.DEBUG, "admin authenticated by md5."); // admin auth success, init AdminFacade and passing the DAO's AdminFacade adminFacade = new AdminFacade(customerDao, companyDao, couponDao); return adminFacade; } Utils.logMessage(this, Severity.ERROR, "admin authentication failed. md5 not match !"); } // login of Company if (clientType == ClientType.COMPANY) { // success auth will return the customer ID Long companyId = companyDao.login(name, password); if (companyId != null && companyId != 0) { // construct a customer with those params Company company = new Company(); company.setId(companyId); company.setCompName(name); company.setPassword(password); // create a CustomerFacade, referring to this company CompanyFacade companyFacade = new CompanyFacade(company); companyFacade.setCompanyDao(companyDao); companyFacade.setCouponDao(couponDao); return companyFacade; } } // login of Customer if (clientType == ClientType.CUSTOMER) { // success auth will return the customer ID Long customerId = customerDao.login(name, password); if (customerId != null && customerId != 0) { // construct a customer with those params Customer customer = new Customer(); customer.setId(customerId); customer.setCustName(name); customer.setPassword(password); // create a CustomerFacade CustomerFacade customerFacade = new CustomerFacade(); // customerFacade need to ref that specific customer ( 1 per client ) customerFacade.setCustomer(customer); // and ref the DAOs ( customer + coupons ) customerFacade.setCustomerDao(customerDao); customerFacade.setCouponDao(couponDao); return customerFacade; } } return null; }
private static void writeCompaniesFile(RandomAccessFile out, ArrayList<Company> list) throws IOException { out.seek(0); for (int i = 0; i < list.size(); i++) { Company c = list.get(i); out.write((c.getCompanyName() + "\n").getBytes()); out.write((c.getCompanySymbol() + "\n").getBytes()); out.write(("" + c.getAmountOfShares() + "\n").getBytes()); out.write(("" + c.getSharePrice() + "\n").getBytes()); } }
/** Executes some demo code on the remote object. */ private void demo() throws Exception { // Test total and cut double before = sampleCompany.total(); System.out.println("Total before cut = " + before); sampleCompany.cut(); double after = sampleCompany.total(); System.out.println("Total after cut = " + after); assertEquals(before / 2.0d, after, 0); System.out.println("Testing done."); }
@Test public void testCreate() { Company cm = new Company(); cm.setName("Windy"); cm.setProductName("Root"); cm.setProductType("Beer"); tx.begin(); em.persist(cm); tx.commit(); assertNotNull(cm.getId()); }
@Test public void testRead() { List<Company> cp = em.createNamedQuery("Company.findByAll", Company.class).getResultList(); assertTrue(cp.size() == 1); assertFalse(cp.isEmpty()); for (Company r : cp) { System.out.println(r.toString()); for (Products p : r.getProducts()) { System.out.println("\t" + p.toString()); } } }
/** * This method will instantiate all of the example instances and insert them into the database * using the given session. */ public void populate(DatabaseSession session) { UnitOfWork unitOfWork = session.acquireUnitOfWork(); unitOfWork.registerObject(Dist_Employee.example1()); unitOfWork.registerObject(Company.example1()); unitOfWork.commit(); }
@Override public SupplierInfoChangedDto paperworkChanged( Long userId, PaperworkDto updatedPaperwork, Company oldPaperwork) { SupplierInfoChangedDto supplierInfoChangedDto = new SupplierInfoChangedDto(); Map<String, String> changedInfo = Maps.newHashMap(); int type = CountryCertificate.check(oldPaperwork.getRegCountry()); PaperworkDto newPaperworkDto = getNewPaperwork(userId, oldPaperwork).getSupplierInfo(); switch (type) { case CountryCertificate.NO_CERTIFICATE: supplierInfoChangedDto.setChanged(false); return supplierInfoChangedDto; case CountryCertificate.ONLY_NEED_BUSINESS_LICENSE: checkBusinessLicense(changedInfo, updatedPaperwork, newPaperworkDto); break; case CountryCertificate.ONLY_NEED_BUSINESS_LICENSE_AND_TAX_NO: checkBusinessLicense(changedInfo, updatedPaperwork, newPaperworkDto); checkTaxNo(changedInfo, updatedPaperwork, newPaperworkDto); break; default: checkBusinessLicense(changedInfo, updatedPaperwork, newPaperworkDto); checkTaxNo(changedInfo, updatedPaperwork, newPaperworkDto); checkOrgCert(changedInfo, updatedPaperwork, newPaperworkDto); } if (!changedInfo.isEmpty()) { supplierInfoChangedDto.setChanged(true); supplierInfoChangedDto.setChangedInfo(changedInfo); } return supplierInfoChangedDto; }
// For [databind#188] public void testMixedRefsIssue188() throws Exception { Company comp = new Company(); Employee e1 = new Employee(1, "First", null); Employee e2 = new Employee(2, "Second", e1); e1.addReport(e2); comp.add(e1); comp.add(e2); String json = MAPPER.writeValueAsString(comp); assertEquals( "{\"employees\":[" + "{\"id\":1,\"name\":\"First\",\"manager\":null,\"reports\":[2]}," + "{\"id\":2,\"name\":\"Second\",\"manager\":1,\"reports\":[]}" + "]}", json); }
/** * This uses a native query because you can't use the DATE() function in MySQL in a JPA query * * @param start startDate * @param end endDate end date ( uses the whole day via DateUtil.getNextDay() ) * @param c Company * @param campaign Campaign (optional) * @param device Device (optional) * @return */ @Override public List<BluetoothFileSendSummary> getBluetoothFileSendSummaryFromBluetoothSend( Date start, Date end, Company company, Campaign campaign, Device device) { int count = 4; HashMap<Integer, Object> parameters = new HashMap<Integer, Object>(); String query = "SELECT DATE(event_date), file, count(*) " + "FROM bluetooth_send " + "WHERE send_status = 1 " + "AND company_id = ?1 " + "AND event_date BETWEEN ?2 AND ?3 "; if (campaign != null) { query += "AND campaign_id = ?" + count + " "; parameters.put(count, campaign.getId()); count++; } if (device != null) { query += "AND device_id = ?" + count + " "; parameters.put(count, device.getId()); count++; } query += "GROUP BY file, DATE(event_date) ORDER BY DATE(event_date)"; Query q = em.createNativeQuery(query); q.setParameter(1, company.getId()); q.setParameter(2, start); q.setParameter(3, DateUtil.getNextDay(end)); for (Map.Entry<Integer, Object> entry : parameters.entrySet()) { Integer position = entry.getKey(); Object param = entry.getValue(); q.setParameter(position, param); } List<BluetoothFileSendSummary> results = new ArrayList<BluetoothFileSendSummary>(); List<Object[]> result = q.getResultList(); for (Object[] object : result) { Date eventDate = (Date) object[0]; String file = (String) object[1]; Long sendCount = (Long) object[2]; BluetoothFileSendSummary item = new BluetoothFileSendSummary(); item.setEventDate(eventDate); item.setFile(file); item.setSendCount(sendCount); item.setCompany(company); item.setCampaign(campaign); item.setDevice(device); results.add(item); } return results; }
/** full constructor */ public Trust clone(long id) { Trust clone = new Trust(id); if (this.companyByCompanyid != null) { Company companyByCompanyidClone = companyByCompanyid.clone(id--); clone.companyByCompanyid = companyByCompanyidClone; } if (this.companyBySolicitorcompanyid != null) { Company companyBySolicitorcompanyidClone = companyBySolicitorcompanyid.clone(id--); clone.companyBySolicitorcompanyid = companyBySolicitorcompanyidClone; } clone.solicitorname = solicitorname; clone.issuperfund = issuperfund; clone.reviewdeeds = reviewdeeds; clone.wealthbyemployment = wealthbyemployment; clone.wealthbyinvestments = wealthbyinvestments; clone.wealthbyother = wealthbyother; clone.wealthbyotherinfo = wealthbyotherinfo; // clone.applications = applications; return clone; }
@Override public int hashCode() { int result = lastDateUpdate != null ? lastDateUpdate.hashCode() : 0; result = 31 * result + (callList != null ? callList.hashCode() : 0); result = 31 * result + (status != null ? status.hashCode() : 0); result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (company != null ? company.hashCode() : 0); result = 31 * result + (event != null ? event.hashCode() : 0); return result; }
/** Max length = 100 */ public final void testValidateNamePropertyLength() { company.setName( "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"); // In french Errors errors = companyValidator.validate(company); assertEquals("le nom est trop long", errors.getFieldError("name", Locale.FRENCH)); // In English errors = companyValidator.validate(company); assertEquals("name is too long", errors.getFieldError("name", Locale.ENGLISH)); // EveryThing OK company.setName( "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"); errors = companyValidator.validate(company); assertFalse(errors.hasFieldErrors("name")); }
@Test @Ignore public void testDelete() { TypedQuery<Company> cb = em.createQuery("select cb from Company cb where cb.name = ?1", Company.class); cb.setParameter(1, "Pepsico"); Company c = cb.getSingleResult(); assertNotNull(c.getId()); tx.begin(); for (Products d : c.getProducts()) { em.remove(d); } em.remove(c); tx.commit(); Company postRemove = em.find(Company.class, 1L); assertNull(postRemove); }
private void computeDeals() { for (Company company : _companies.values()) { while ((company._buyOrders.size() > 0) && (company._sellOrders.size() > 0)) { StockOrder buy = company._buyOrders.get(company._buyOrders.firstKey()); StockOrder sell = company._sellOrders.get(company._sellOrders.firstKey()); if (sell.getPrice() > buy.getPrice()) break; double price = Math.min(buy.getPrice(), sell.getPrice()); int amount = Math.min(buy.getAmount(), sell.getAmount()); String mes = "deal " + buy.getClientName() + " " + buy.getBrokerName() + " " + sell.getClientName() + " " + sell.getBrokerName() + " " + buy.getStockName() + " " + amount + " " + price + "\n"; if (sell.getClientName().equals("StockExchange")) { _cash += price; _stockExchangeStompClient.send("/topic/bDeals-" + buy.getBrokerName(), mes); company._buyOrders.remove(buy.getClientName()); company._sellOrders.remove(sell.getClientName()); company.addDefaultOrder(); } else { _stockExchangeStompClient.send("/topic/bDeals-" + buy.getBrokerName(), mes); _stockExchangeStompClient.send("/topic/bDeals-" + sell.getBrokerName(), mes); company._buyOrders.remove(buy.getClientName()); company._sellOrders.remove(sell.getClientName()); } } } }
public SupplierInfoChangedDto contactInfoChanged( Long userId, ContactInfo updatedContactInfo, ContactInfo oldContactInfo) { SupplierInfoChangedDto supplierInfoChangedDto = new SupplierInfoChangedDto(); ContactInfo newContactInfo = getNewContactInfo(userId, oldContactInfo).getSupplierInfo(); Map<String, String> changedInfo = Maps.newHashMap(); if (!Objects.equal(updatedContactInfo.getName(), newContactInfo.getName())) { changedInfo.put(ChangedInfoKeys.contactInfoName(), updatedContactInfo.getName()); updatedContactInfo.setName(null); } if (!Objects.equal(updatedContactInfo.getEmail(), newContactInfo.getEmail())) { changedInfo.put(ChangedInfoKeys.contactInfoEmail(), updatedContactInfo.getEmail()); updatedContactInfo.setEmail(null); } if (!Objects.equal(updatedContactInfo.getMobile(), newContactInfo.getMobile())) { changedInfo.put(ChangedInfoKeys.contactInfoMobile(), updatedContactInfo.getMobile()); updatedContactInfo.setMobile(null); } Company company = companyDao.findByUserId(userId); if (!Strings.isNullOrEmpty(company.getSupplierCode())) { if (!Objects.equal(updatedContactInfo.getOfficePhone(), newContactInfo.getOfficePhone())) { changedInfo.put(ChangedInfoKeys.contactInfoPhone(), updatedContactInfo.getOfficePhone()); updatedContactInfo.setOfficePhone(null); } } if (!changedInfo.isEmpty()) { supplierInfoChangedDto.setChanged(true); supplierInfoChangedDto.setChangedInfo(changedInfo); } return supplierInfoChangedDto; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CallListCompany)) return false; CallListCompany that = (CallListCompany) o; if (callList != null ? !callList.equals(that.callList) : that.callList != null) return false; if (company != null ? !company.equals(that.company) : that.company != null) return false; if (event != null ? !event.equals(that.event) : that.event != null) return false; if (lastDateUpdate != null ? !lastDateUpdate.equals(that.lastDateUpdate) : that.lastDateUpdate != null) return false; if (status != null ? !status.equals(that.status) : that.status != null) return false; if (user != null ? !user.equals(that.user) : that.user != null) return false; return true; }
/** * groupId can be null if the report does not expand groups * * @param id * @param dataList * @param groupId */ public Report( int id, Map<String, DataDto> dataList, Integer groupId, Map<Integer, Set<GroupEntry>> groupEntriesByCompany, List<ConfidenceGrade> cgs, Map<Integer, List<ListItem>> codeListsByCodeList, List<Lock> locks, Company company, Run run, RunModelTag tag, TagMap tagMap, Map defaultRunIdMap) { super(); this.id = id; this.dataList = dataList; this.groupId = groupId; this.groupEntriesByCompany = groupEntriesByCompany; this.cgs = cgs; this.codeListsByCodeList = codeListsByCodeList; if (null == locks) { this.locks = new ArrayList<Lock>(); } else { this.locks = locks; } this.company = company; this.showAllHeaders = false; this.run = run; if (null == tag) { this.tagId = 0; } else { if (null == company) { this.tagId = tag.getId(); } else { this.tagId = tag.getRunModelCompanyTag(company.getId()).getId(); } } this.tag = tag; this.tagMap = tagMap; this.defaultRunIdMap = defaultRunIdMap; }
public static TestSuite getInsertObjectTestSuite() { TestSuite suite = new TestSuite(); suite.setName("InserfaceWithoutTablesInsertObjectTestSuite"); suite.setDescription( "This suite tests the insertion of each object in the interface model (without tables)."); suite.addTest(new InsertObjectTest(Film.example2())); suite.addTest(new InsertObjectTest(Secretary.example2())); suite.addTest(new InsertObjectTest(Company.example3())); suite.addTest(new InsertObjectTest(CourseDeveloper.example1())); suite.addTest(new InsertObjectTest(Email.example2())); // suite.addTest(new InsertObjectTest(Employee.example3())); Cannot use insert test on emp as // bi-1-1 suite.addTest(new InsertObjectTest(PersonnelManager.example1())); suite.addTest(new InsertObjectTest(Phone.example1())); suite.addTest(new InsertObjectTest(ProductDeveloper.example3())); suite.addTest(new InsertObjectTest(ProductManager.example1())); suite.addTest(new InsertObjectTest(Receptionist.example1())); return suite; }
public void sell() { for (Company x : _market.getCompanies()) { if (x.getRisk() > _confidence || x.numLeft() < 3 || x.getRisk() < _confidence - 15) { if (_stocks.get(x) == 1) { _stocks.remove(x); } else { _stocks.put(x, _stocks.get(x) - 1); } _money += x.getPrice(); x.gain(); break; } else { _happy = true; } } }
private void disconnectClient(String client) { for (Company company : _companies.values()) { StockOrder order = company.getBuyOrders().get(client); while (order != null) { // remove buy orders company.getBuyOrders().remove(client); order = company.getBuyOrders().get(client); } order = company.getSellOrders().get(client); while (order != null) { // sell buy orders company.getSellOrders().remove(client); order = company.getSellOrders().get(client); } } _numActiveClients--; for (StockExchangeBroker broker : _brokers) broker.removeClient(client); // //_brokers.get(_clients.get(client)).decClientNum(); TODO: // _clients.remove(client); _stockExchangeStompClient.unsubscribe("/topic/cDeals-" + client, this); _stockExchangeStompClient.send("/topic/cDisconnected", "disconnected " + client + "\n"); }
public void invest() { _oldmoney = _money; // assuming this goes first. for (Company y : _market.getCompanies()) { if (y.getRisk() < _confidence && y.numLeft() > 0 && y.getPrice() < _money) { if (_stocks.containsKey(y)) { _stocks.put(y, (_stocks.get(y) + 1)); } else { _stocks.put(y, 1); } y.sell(); _money -= y.getPrice(); break; } else { _happy = true; } } }
@Test public void testUpdate() { Company cp = em.createNamedQuery("Company.findByName", Company.class) .setParameter("name", "Windy") .getSingleResult(); assertNotNull(cp.getId()); String originalName = cp.getName(); String newName = "Chicago Beverage"; tx.begin(); cp.setName(newName); tx.commit(); assertNotEquals(originalName, cp.getName()); assertTrue(newName.equals(cp.getName())); tx.begin(); cp.setName(originalName); tx.commit(); }
@Test public void testCompanyNameLoaderLoadData() throws Exception { List<Object> expectedListCompany = new ArrayList<Object>(); Company company1 = new Company(); company1.setCode("VND"); company1.setCompanyName("CT chung khoan VNDIRECT"); Company company2 = new Company(); company2.setCode("SSI"); company2.setCompanyName("CT chung khoan SSI"); expectedListCompany.add(company1); expectedListCompany.add(company2); Mockito.when( elasticSearchClient.getDataByIndex( Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any())) .thenReturn(expectedListCompany); loader.load(); List<Object> listCompany = (List<Object>) memory.get("COMPANY_LIST", "COMPANY_LIST"); Assert.assertEquals(expectedListCompany, listCompany); }
public void populate(DatabaseSession session) { PopulationManager manager = PopulationManager.getDefaultManager(); Cat cat = Cat.example1(); session.writeObject(cat); manager.registerObject(cat, "catExample1"); Dog dog = Dog.example1(); session.writeObject(dog); manager.registerObject(dog, "dogExample1"); cat = Cat.example2(); session.writeObject(cat); manager.registerObject(cat, "catExample2"); dog = Dog.example2(); session.writeObject(dog); manager.registerObject(dog, "dogExample2"); cat = Cat.example3(); session.writeObject(cat); manager.registerObject(cat, "catExample3"); dog = Dog.example3(); session.writeObject(dog); manager.registerObject(dog, "dogExample3"); Company company = Company.example1(); session.writeObject(company); manager.registerObject(company, "example1"); manager.registerObject(((Vector) company.getVehicles().getValue()).firstElement(), "example1"); company = Company.example2(); session.writeObject(company); manager.registerObject(company, "example2"); company = Company.example3(); session.writeObject(company); manager.registerObject(company, "example3"); Person person = Person.example1(); session.writeObject(person); manager.registerObject(person, "example1"); // populate the data for duplicate field testing session.writeObject(A_King2.exp1()); session.writeObject(A_King2.exp2()); session.writeObject(A_1_King2.exp3()); session.writeObject(A_2_King2.exp4()); session.writeObject(A_2_1_King2.exp5()); UnitOfWork unitOfWork = session.acquireUnitOfWork(); person = Person.example2(); unitOfWork.registerObject(person); unitOfWork.commit(); manager.registerObject(person, "example2"); manager.registerObject(person.bestFriend, "example5"); manager.registerObject(person.representitive, "example4"); person = Person.example3(); session.writeObject(person); manager.registerObject(person, "example3"); Computer computer = Computer.example1(); session.writeObject(computer); manager.registerObject(computer, "example1"); computer = Computer.example2(); session.writeObject(computer); manager.registerObject(computer, "example2"); computer = Computer.example3(); session.writeObject(computer); manager.registerObject(computer, "example3"); computer = Computer.example4(); session.writeObject(computer); manager.registerObject(computer, "example4"); computer = Computer.example5(); session.writeObject(computer); manager.registerObject(computer, "example5"); JavaProgrammer JP = JavaProgrammer.example1(); session.writeObject(JP); manager.registerObject(JP, "example1"); JP = JavaProgrammer.example2(); session.writeObject(JP); manager.registerObject(JP, "example2"); // Added to test bug 3019934. unitOfWork = session.acquireUnitOfWork(); Alligator alligator = new Alligator(); alligator.setFavoriteSwamp("Florida"); alligator.setLatestVictim(JavaProgrammer.steve()); unitOfWork.registerObject(alligator); manager.registerObject(alligator, "example1"); unitOfWork.commit(); // Added to test bug 6111278 unitOfWork = session.acquireUnitOfWork(); Entomologist bugguy = new Entomologist(); bugguy.setId((int) System.currentTimeMillis()); bugguy.setName("Gary"); bugguy = (Entomologist) unitOfWork.registerObject(bugguy); Insect insect = new GrassHopper(); insect.setIn_numberOfLegs(4); insect.setEntomologist(bugguy); bugguy.getInsectCollection().add(insect); unitOfWork.commit(); }