In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. Configure the JPA project
JPA is a persistence specification similar to Hibernate and has become part of the Java EE 5 specification. JPA uses Java 5 annotations to control the mapping of normal Java classes (POJO) to database tables.
You can create an JPA-enabled project by creating any supported underlying project type, such as a Java or Web project, and then add JPA facets to the project from the MyEclipse menu. Right-click the project to add the JPA facet, and then select MyEclipse > Project Facets > Install JPA Facet from the menu. At the same time, you can add multiple facets to the project at the same time by opening the Project Facets property of the project.
Provide persistence
MyEclipse provides support for OpenJPA, Hibernate, and EclipseLink JPA providers.
Database configuration
Associate projects with databases and schemas to support design-time tools. As shown in the following figure, the project is associated with the database driver for the local MyEclipse Derby database.
In addition to relying on the libraries provided with MyEclipse, you can also click the download icon
Add user libraries to include in the project.
At the same time, you can also right-click the project and select "Properties" from the menu, expand MyEclipse > Project Facets, then select Java Persistence, and open the Java Persistence properties page to change the database driver association of the JPA project at any time.
2. Reverse engineer entities and DAO from the database
Right-click a JPA project and choose "Generate Entities & DAOs" from the menu. You can choose to use the MyEclipse reverse engineering tool or the DALI entity generator to make the choice, which will launch the appropriate JPA reverse engineering wizard.
Right-click the table in the DB Browser view to generate the entity.
The reverse engineering process is completely customizable. Using the JPA reverse engineering wizard, you can select the artifact to generate and the database table on which the artifact is based.
MyEclipse can also generate DAO findBy queries with support for paging results. The resulting paging API provides fine-grained program control for the DAO client to navigate to a specific row number of the result set and get n entities.
Here are several sample snippets of code generated by the reverse engineering processor:
3. Advanced entity editing tools
MyEclipse Java persistence perspective
The MyEclipse Java Persistence perspective provides the best editor and view layout for jpa-oriented tasks.
JPA Details view
Entity comments can be easily edited through the JPA Details view.
JPA Diagram Editor
The JPA Diagram editor makes it easy for you to create new entities or edit entities in existing JPA projects.
JPA Annotation Table and Column Content Assist
JPA Entity Validation
Errors in the mapping can be detected and displayed in the editor and Problems view.
JPA Entity Validator can be enabled or disabled at the project level.
4. Advanced Spring-JPA integration
Spring 2 support
When adding JPA constructs to projects that already have Spring constructs, you can choose advanced Spring-JPA support (and vice versa). This level of support allows the JPA tool to be used with the project's Spring artifacts. The following figure shows the Spring-JPA project configuration wizard.
Select Spring-JPA support, main bean profile, and customize bean id and transaction support.
Reverse engineering entities and Spring DAO in databases
For projects configured to support advanced Spring-JPA features, you can generate Spring-compliant DAO in addition to generating entity classes from the database schema. During reverse engineering, the Spring application context file is updated with the generated bean entry for each DOA class.
Generate Spring DAO:
The generated Spring application context file:
The generated Spring DAO extends from Spring's JpaDaoSupport:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.