A simple JPA example written with eclipse

Source: Internet
Author: User
Tags table name

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.