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 and add the following annotations:

@ManagedBean (name="course") 
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:


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 live online training, plus books, videos, and digital content from nearly 200 publishers.