1. Create a new JPA project first:
2. Write the project name, click Next, then Next, if the first build JPA project may be stuck in the following interface, prompted to select the user library, click on the red circle download, choose the one that corresponds to your eclipse, mine is Kepler ( You can see it on the screen when you start Eclipse), tick on, then finish:
3. This is a well-written example, first look at the engineering structure:
User class under 4.beans package (creation: Right-click package Name-> New-> JPA Entity):
where @Table is to set the database table name associated with the class
@Id is the primary key
operating class under the 5.dao package:
test class under the 6.test package:
7. Configuration file Persistence.xml (under the Meta-inf directory):
8. The database used here is MySQL, because there is no automatic generation table, in MySQL first manually created the table user (name varchar () primary key, pwd varchar (20)), Also remember to add the MySQL driver package to the project.