TJDO Tutorial: Step 1

Step 1 | Step 2 | Step 3 | Step 4 | Step 5

Step 1: Create a normal Java class

The first step in creating a PersistenceCapable class is to write a class file much as you normally would. In our example, we will be persisting a Person object. (The source code for this tutorial can be downloaded here.)

package test;

public class Person
{
  String firstName;
  String lastName;
  int age = 0;

  /**
   * Default constructor required by JDO.
   */
  public Person() {}

  /**
   * Constructor.
   * @param first  First name.
   * @param last   Last name.
   * @param age    The Person's age.
   */
  public Person(String first, String last, int age)
  {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
  }

  // ... Define getters and setters
}

Notice the presence of a default constructor. This is required by any PersistenceCapable class, and the class will fail the class enhancing step if this is not present.



TJDO Home SourceForge.net