3.3. Defining a Class

The first step in using JDO is to create a persistence-capable Java class. For the purposes of the examples in this book, it is assumed that byte code enhancement is being used, so all that is needed is a Java class. The following code snippet shows the code for a class called Author, which represents the author of a book:

package com.corejdo.examples.model;

public class Author {

  private String name;

  public Author (String name) {

      this.name = name;
  }

  protected Author () {}

  public String getName () {

    return name;
  }

  public void setName (String name) {

    this.name = name;
  }
}

This class is relatively simply with just one string field. JDO can, of course, support much more than this; see Section 3.9 for more details on what is ...

Get Core Java™ Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.