hibernate.cfg.xml配置信息

标签: Hibernate Struts

[1].[代码] [Java]代码 跳至 [1]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
hibernate.cfg.xml配置文件
 
  <?xml version= '1.0' encoding= 'UTF-8' ?>
<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
  
<hibernate-configuration>
<session-factory>
  <property name= "dialect" >
   org.hibernate.dialect.SQLServerDialect
  </property>
  <property name= "connection.url" >
   jdbc:sqlserver: //localhost:1433;databaseName=newsDB
  </property>
  <property name= "connection.username" >sa</property>
  <property name= "connection.password" > 123456 </property>
  <property name= "connection.driver_class" >
   com.microsoft.sqlserver.jdbc.SQLServerDriver
  </property>
  
  <property name= "show_sql" > true </property>
   
       <property name= "hibernate.cache.use_second_level_cache" > true </property> 
       <property name= "hibernate.cache.use_query_cache" > true </property>  
       <property name= "hibernate.cache.region.factory_class" >org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
  <property name= "c3p0.max_size" > 30 </property>
  <property name= "c3p0.min_size" > 5 </property>
  <property name= "c3p0.timeout" > 1800 </property>
  <property name= "c3p0.max_statements" > 50 </property>
  <mapping resource= "com/entity/NewsInfo.hbm.xml" />
  <mapping resource= "com/entity/NewsTypeInfo.hbm.xml" />
  <mapping resource= "com/entity/UserInfo.hbm.xml" />
      
</session-factory>
</hibernate-configuration>
 
  hibernate 的工厂获取方式 ---》更 3 不同
package com.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;
public class HibernateSessionFactory {
  private static Session session;
  private static SessionFactory sessionFatory = null ;
  static {
   Configuration cfg = new Configuration().configure( "/hibernate.cfg.xml" );
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
    sessionFatory = cfg.buildSessionFactory(serviceRegistry); 
  }
  public static Session getSession() {
   return  sessionFatory.openSession();
  }
  public static SessionFactory getSessionFatory() {
   return sessionFatory;
  }
  public static void setSessionFatory(SessionFactory sessionFatory) {
   HibernateSessionFactory.sessionFatory = sessionFatory;
  }
     
  
}
在实体 里面放入xml配置
<cache usage= "read-write" />
包  如下  非常重要

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hibernate.cfg.xml文件是Hibernate框架中的配置文件之一,用于配置Hibernate的各种属性和参数。在该文件中,可以配置数据源、数据库连接池、映射文件、缓存策略等等。 其中,常用的配置属性包括: 1. hibernate.connection.driver_class:指定数据库驱动程序的类名。 2. hibernate.connection.url:指定数据库的连接URL。 3. hibernate.connection.username:指定连接数据库所需的用户名。 4. hibernate.connection.password:指定连接数据库所需的密码。 5. hibernate.dialect:指定数据库方言,用于生成针对具体数据库的SQL语句。 6. hibernate.show_sql:设置是否在控制台打印生成的SQL语句。 7. hibernate.format_sql:设置是否格式化生成的SQL语句。 此外,在Hibernate.cfg.xml文件中还可以配置其他相关属性,如连接池的最大连接数、最小连接数等。可以通过修改这些配置属性来满足具体的业务需求。 需要注意的是,Hibernate.cfg.xml文件的配置可以使用properties属性文件格式,也可以使用XML格式进行配置。可以根据具体的需求选择适合的配置方式。 总之,Hibernate.cfg.xml文件是Hibernate框架中的重要配置文件,用于配置各种属性和参数,以便进行数据库操作和映射。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Hibernate.cfg.xml文件的配置](https://blog.csdn.net/u022812849/article/details/40827561)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [hibernate.cfg.xml配置总结](https://blog.csdn.net/hiyu2218/article/details/4169585)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值