Hibernate reverse engineering steps and DAO Type cannot choose Spring DAO solution

1 Let's take a look at the detailed steps and configuration of hibernate reverse engineering:

①In the MyEclipse Database Explorer perspective, right-click the data table to be operated and select Hibernate Reverse Engineering

② Do the following configuration in the pop-up Hibernate Reverse Engineering window:

    Java src folder:/login/src

    Java package:com.coridc.login.model.domain

    选中Hibernate mapping file for each database table

    选中Update hibernate configuation with mapping file location

    Check Java Data Object

    Uncheck Create abstract class and leave Base president class blank

    Check Java Data Access Object

    选中Generate precise findBy methods

    DAO Type choose spring  DAO

    At this point, the Spring config file will automatically fill in WebRoot/WEB-INF/applicationContext.xml

    At this point the SessionFactory id will be automatically filled in mySessionFactory - (WebRoot/WEB-INF/applicationContext.xml)

    不选Use custom templates

    Next;

③ In this window, just change the ID Generator type to native -> Finish.

2 However, in the red configuration in the above 2, there may be cases where Basic DAO and JNDI DAO are optional but Spring DAO is not .

The solution is as follows:

Go to MyEclipse Java Enterprise Perspective, right-click on the project -> Properties -> MyEclipse -> Spring, fill in xml at Config file extensions, then click Add, select Spring's general configuration file applicationContext.xml according to the directory, OK, OK.

Then go back to step 1, step, step, step, step, get it, The End.

Note: There is an updated version of this method. For details, please refer to the blog post on this site: About the solution to Hibernate's inability to select Spring DAO Type during reverse engineering [Updated version]

 

 

3 Three and a half files generated by Hibernate reverse engineering

①com.coridc.login.model.domain.Student.java (the abstraction of database tables     using object-oriented Java language generated by MyEclipse )

    ②com.coridc.login.model.domain.StudentDAO.java (encapsulates some operations on the database automatically generated by MyEclipse)

    ③com.coridc.login.model.domain.Student.hbm.xml (the definition of mapping the fields in the database table and the attributes of the POJO class)

    ④ Generate a bean code with an id of StudentDAO in the Spring general configuration file applicationContext.xml

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326338529&siteId=291194637