Similar to the previous article, there are some basic things.
This is JPA + Spring MVC 3.0.
1. Create a Project
2. Add JPA Support
3. We use Hibernate as an example to set the JPA Provider to Hibernate.
4. Add persistence. xml, where the standard location should be src/main/resources/META-INF, so we need to create a folder for the resource and META-INF
5. Go back to project structure> modules> JPA and add the created persistence. xml file to JPA.
6. Modify POM. XML to add two jars, one being hibernate-entitymanager and the other being mysql connector.
7. modify our persistence. xml (here you can also do not add persistence. xml, just build the META-INF, and then generate it from step 1)
org.hibernate.ejb.HibernatePersistence
7. View-> Tools windows-> DataBase creates a DataSource
8. View-> Tools Windows-> Persistence-> Generate Persistence Mapping-> By Database Schema
Selected Location
9. At this time, we have the generated Entity.
10. Note that at this time, if you use Console> to perform hql queries, the system will display an error. Now you can ignore this issue and wait for the build to complete.
11. Check the persistence. xml file at this time. Check whether the class has been added to the xml file. The complete persistence. xml should be like this.
org.hibernate.ejb.HibernatePersistence com.springapp.modlels.OfficeEntity
12. add. jsp and modify the controller.
"/" ="message", "Hello world!" "hello"= RequestMethod.GET, value="add""message", "Hello world!"= Persistence.createEntityManagerFactory("personDB"== "test" "add"
Run it.
At this time, if we return persistence and console hql, there will be no problem.
Note: The No suitable Driver problem may occur in JBoss, starting with getTransaction (). I don't know why this problem occurs and it runs normally in Tomcat.