Hibernate 配置hibernate.cfg.xml

比眉伴天荒 2023-10-06 12:25 69阅读 0赞
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  5. <hibernate-configuration>
  6. <!-- 配置数据库连接 connection -->
  7. <session-factory>
  8. <!-- 数据库驱动 -->
  9. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  10. <!-- 数据库地址 localhost可以写作 jdbc:mysql:/// -->
  11. <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/database_name</property>
  12. <!-- 数据库用户名 -->
  13. <property name="hibernate.connection.username">username</property>
  14. <!-- 数据库用户的密码 -->
  15. <property name="hibernate.connection.password">password</property>
  16. <!-- 数据库方言 MySQL -->
  17. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  18. <!-- 连接池 C3P0 -->
  19. <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
  20. <!-- 格式化输出生成的SQL语句 -->
  21. <property name="hibernate.show_sql">true</property>
  22. <property name="hibernate.format_sql">true</property>
  23.      <!-- hibernate根据映射关系自动建表
  24. 默认: 不会创建表
  25. create: 没有表就创建,有表就删除重建。
  26. create-drop: 没有表就创建,有表就删除重建,使用完自动删表。
  27. update: 没有表就创建表,否则使用现有的表。
  28. validate: 不会创建表
  29. -->
  30. <property name="hibernate.hbm2ddl.auto">validate</property>
  31. <!-- 加载映射文件 -->
  32. <mapping resource="package.name.ClassName.hbm.xml" />
  33. </session-factory>
  34. </hibernate-configuration>

发表评论

表情:
评论列表 (有 0 条评论,69人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Hibernate+JNDI配置

    刚开始使用JNDI,网上也查了不少资料,磕磕盼盼鼓捣了大半天才成功,在此记录一下。 介绍 首先还是再啰嗦两句,介绍一下JNDI技术。 JNDI是Java 命名和目录