用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

java hibernate.cfg.xml配置信息

2015-01-07 作者: java源代码大全举报

[java]代码库

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"/>
包  如下  非常重要

//源代码片段来自云代码http://yuncode.net
			


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...