コード例 #1
0
  protected void setup() {
    // save current null values for later restoration
    saveDefaultDefaultNullValues = ConversionManager.getDefaultManager().getDefaultNullValues();
    saveDefaultNullValues =
        getSession().getLogin().getPlatform().getConversionManager().getDefaultNullValues();
    getSession()
        .getLogin()
        .getPlatform()
        .getConversionManager()
        .setDefaultNullValues(new Hashtable());
    getSession().getLogin().setDefaultNullValue(String.class, "null");
    getSession().getLogin().setDefaultNullValue(int.class, new Integer(-1));
    // Reinit mappings.
    for (DatabaseMapping mapping : getSession().getDescriptor(Address.class).getMappings()) {
      if (mapping.isDirectToFieldMapping()) {
        mapping.preInitialize(getAbstractSession());
      }
    }
    getAbstractSession().beginTransaction();

    employee = new Employee();
    employee.setFirstName("Fred");
    employee.setLastName("Flintstone");
    employee.setSalary(22);
    employee.setGender("Male");
    Address address = new Address();
    address.setCity(null);
    employee.setAddress(address);

    getAbstractSession().writeObject(employee);
    // force the salary to be NULL
    getSession()
        .executeNonSelectingCall(
            new SQLCall("update SALARY set SALARY = null where EMP_ID = " + employee.getId()));
  }
コード例 #2
0
 protected void changeObject() {
   Employee employee = (Employee) this.workingCopy;
   // Direct to field
   employee.setFirstName(new String(employee.getFirstName().getBytes()));
   // Object type
   employee.setGender(new String(employee.getGender().getBytes()));
   // Transformation
   employee.setNormalHours(employee.getNormalHours().clone());
   // Aggregate
   employee.setPeriod(
       new EmploymentPeriod(
           employee.getPeriod().getStartDate(), employee.getPeriod().getEndDate()));
   // One to many private/public
   employee.setPhoneNumbers((Vector) employee.getPhoneNumbers().clone());
   employee.setProjects((Vector) employee.getProjects().clone());
   employee.setManagedEmployees((Vector) employee.getManagedEmployees().clone());
   // Direct collection
   employee.setResponsibilitiesList((Vector) employee.getResponsibilitiesList().clone());
   // One to one private/public
   employee.getAddress();
   employee.getManager();
 }