<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/kong?autoReconnect=true
</property>
<property name="connection.username">rt</property>
<property name="connection.password">r</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">kfc</property>
<!-- C3P0 -->
<property name="hibernate.c3p0.max_size">2000</property>
<property name="hibernate.c3p0.min_size">8</property>
<property name="hibernate.c3p0.timeout">25000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">18000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property> <property name="hibernate.c3p0.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.show_sql">false</property>
<mapping resource="Bean/Messag.hbm.xml" />
<mapping resource="Bean/Message1.hbm.xml" />
<mapping resource="Bean/Messa.hbm.xml" />
<mapping resource="Bean/Messag33.hbm.xml" />
<mapping resource="Bean/Us.hbm.xml" />
<mapping resource="Bean/Tk.hbm.xml" />
<mapping resource="Bean/Meage2.hbm.xml" />
<mapping resource="Bean/Ssage4.hbm.xml" />
<mapping resource="Bean/Mes.hbm.xml" />
<mapping resource="Bean/Msse52.hbm.xml" />
<mapping resource="Bean/Essage53.hbm.xml" />
</session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/kong?autoReconnect=true
</property>
<property name="connection.username">rt</property>
<property name="connection.password">r</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">kfc</property>
<!-- C3P0 -->
<property name="hibernate.c3p0.max_size">2000</property>
<property name="hibernate.c3p0.min_size">8</property>
<property name="hibernate.c3p0.timeout">25000</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">18000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property> <property name="hibernate.c3p0.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.show_sql">false</property>
<mapping resource="Bean/Messag.hbm.xml" />
<mapping resource="Bean/Message1.hbm.xml" />
<mapping resource="Bean/Messa.hbm.xml" />
<mapping resource="Bean/Messag33.hbm.xml" />
<mapping resource="Bean/Us.hbm.xml" />
<mapping resource="Bean/Tk.hbm.xml" />
<mapping resource="Bean/Meage2.hbm.xml" />
<mapping resource="Bean/Ssage4.hbm.xml" />
<mapping resource="Bean/Mes.hbm.xml" />
<mapping resource="Bean/Msse52.hbm.xml" />
<mapping resource="Bean/Essage53.hbm.xml" />
</session-factory>
解决方案 »
- 事务问题!!说什么没有全局的事务可以回滚!!
- 求EJB好书推荐!
- 我在做个B/S 模式的邮件系统 用的是javaMail服务器
- spring配置文件加载sessionFactory的问题
- jquery的ajax提交form,封装进action中的一个变量的变量
- 什么是向上转型,什么是向下转型
- weblogic的缓存怎么删除呀?
- OSworkflow如何获得当前用户有权查看的step
- 关于web报表的问题
- 一个程序问题,是关于文件读写的,是RandomAccessFile 类的,大家帮忙看看阿,如果打家觉得分不够我可以在加的,问题就在源文件里面的
- java.sql.SQLException: 未执行语句句柄
- GlassFish的JPA查询数据的问题
工具类
package Util;import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;/**
* Configures and provides access to Hibernate sessions, tied to the
* current thread of execution. Follows the Thread Local Session
* pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory { /**
* Location of hibernate.cfg.xml file.
* Location should be on the classpath as Hibernate uses
* #resourceAsStream style lookup for its configuration file.
* The default classpath location of the hibernate config file is
* in the default package. Use #setConfigFile() to update
* the location of the configuration file for the current session.
*/
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION; static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
} return session;
} /**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
} /**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null); if (session != null) {
session.close();
}
} /**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
} /**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
} /**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}}
Transaction tx=getSession().beginTransaction();
getSession().delete(m);
tx.commit();
getSession().clear();
getSession().close();
DaoImpl中的处理过程,
hibernate本来就是有严格的jdbc操作工作流程,这些你尽量不要侵入,也就是说不要随便自己给关掉,或者打开,除非你有把握不会冲突才去这样操作...