The table and fields in the Librarian.hbm.xml file in Hibernate are shown in red-IDEA configuration DataSource

In the simple summary of novice web development (13)-related optimization of database connection (use of Hibernate) , the table and fields in the newly created Librarian.hbm.xml file appear in red, as shown in the figure:

In fact, the reason for this is that our Librarian.hbm.xml is not associated with the corresponding DataSource. The following is mainly through a few steps of configuration to solve this problem

  • 1. Click the Database in the upper right corner of the IDEA project to display the interface as shown in the figure, and click + in the upper left corner of the small database window

  • 2. After clicking +, the following interface will pop up. Select the corresponding database according to the database configured in the project. Since the HSQLDB database is currently used in the project, select DataSource->HSQLDB in turn

Because in Xiaobai novice web development simple summary (13)-database connection related optimization (the use of Hibernate) (this has not been summarized, I will update the address after writing it!!) HSQLDB database is used.

  • 3. The following interface pops up, fill in the URL of the database, the corresponding Path, Name, and Database are automatically filled in, and User and Password need to be filled in, and click OK

  • 4. The previous interface in the first step is updated as shown in the figure below

  • 5. After entering Librarian.hbm.xml, in the place where the error is reported, click and the following small window will pop up, click "Assign Data Source"

  • 6. On the pop-up interface, the previously added DataSource will appear. After clicking Ok, Librarian.hbm.xml is no longer reported in red.

After the above 6 steps, we have now successfully connected the database to the project. Very happy, and finally solved another problem.

Guess you like

Origin blog.csdn.net/nihaomabmt/article/details/114688878