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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值