The server automatically generates the Integer primary key for the id property because it is annotated with @GeneratedValue (strategy = Generation.Type.AUTO).
In addition to the generated source we need to add a constructor that will take the author and title Strings.
The Book.java is an ordinary POJO declared as an Entity Bean to the server by the annotations @Entity and the primary key field @Id (and @GeneratedValue). The strategy for GeneratedValue defines how the persistence provider must generate the annotated primary key.
In this case we can see that our primary key is an Integer called id and the strategy is the default GenerationType.AUTO. As suggested, this means that the persistence provider will create a new id for all new entities added to the database.

As you can see, the Book class has three properties, java.lang.Integer id our primary key, java.lang.String title and java.lang.String author. These will map to the fields in the table that will be created for us by the persistence provider.
We've added getters and setters and an additional constructor that takes title and author parameters so we can create an entity from new keyword.
See what I did here
|