public static SessionFactory getFactory(){
Configuration configuration =new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
hibernate配置
<!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="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test </property>
<property name="hibernate.connection.username">root </property>
<property name="hibernate.connection.password">root </property>
<property name="hibernate.connection.pool.size">20 </property>
<property name="hibernate.show_sql">true </property>
<property name="jdbc.fetch_size">50 </property>
<property name="jdbc.batch_size">23 </property>
<property name="jdbc.use_scrollable_resultset">false </property>
<property name="Connection.useUnicode">true </property>
<property name="connection.characterEncoding">gbk </property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect </property>
<mapping class="qwer.re.tte.StudentBean"/>
<mapping class="qwer.re.tte.TeacherBean"/>
<mapping class="qwer.re.tte.StuTea"/>
</session-factory>
</hibernate-configuration>