The use of Hibernate framework (2)

After a day and a half last time, IDEA+MySQL database+Hibernate was successfully created; today, it took one night to successfully create half a maven project of IDEA+SqlServer+Hibernate+.

Why is it called half maven? Because my pom file has not been able to successfully import the sqlserver driver, so I tried to use the maven+jar package, which is the package that cannot be imported in the pom file, and I manually added it to the project! ! !

The basic steps are still the same as using the mysql database, but the content in the hibernate.cfg.xml configuration file is different, as follows:

<session-factory>
    <property name="connection.url">jdbc:sqlserver://localhost:1433</property>
    <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="connection.username">sa</property>
    <property name="connection.password">123456</property>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>

    <mapping resource="UserTable.hbm.xml"/>
    <!-- <property name="connection.username"/> -->
    <!-- <property name="connection.password"/> -->

    <!-- DB schema will be updated if needed -->
    <!-- <property name="hibernate.hbm2ddl.auto">update</property> -->
  </session-factory>

Note: This hibernate.cfg.xml configuration file should be under the resources path, and the url in the configuration file does not need to write the name of the database.

Guess you like

Origin blog.csdn.net/weixin_45757641/article/details/121480832