Creating entities

We have already created JavaBeans for Course, Person, Student, and Teacher. We will now convert them to JPA entities using the @Entity annotation. Open Course.java and add the following annotations:

@ManagedBean (name="course") 
@RequestScoped 
@Entity 
public class Course implements Serializable 

The same bean can act as a managed bean for JSF and an entity for JPA. Note that if the name of the class is different from the table name in the database, you will need to specify a name attribute of the @Entity annotation. For example, if our Course table were called SchoolCourse, then the entity declaration would be as follows:

@Entity(name="SchoolCourse") 

To specify the primary key of the Entity, use the @Id annotation. In the ...

Get Java EE 8 Development with Eclipse 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.