`
空指针异常
  • 浏览: 21550 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类

Hibernate 4 知识点记载

阅读更多
下载地址:
http://sourceforge.net/projects/hibernate/files/

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>

        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/ssh</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>
        
        <mapping class="com.utstar.model.User"/>
    </session-factory>

</hibernate-configuration>


获取SessionFactory
public class HibernateUtil {
	private static SessionFactory sf;

	static {
		Configuration cfg = new Configuration().configure();

		StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
		ServiceRegistry sr = serviceRegistryBuilder.applySettings(
				cfg.getProperties()).build();
		sf = cfg.buildSessionFactory(sr);
	}

	public static SessionFactory getSessionFactory() {
		return sf;
	}
}


与hibernate3的变化,参考如下帖:
http://hi.baidu.com/austincao/item/fc9907da3d854e44fa576861

hibernate 执行原生SQL出现“SQL Error: 0, SQLState: S0022”解决方案文章,参考
http://www.tuicool.com/articles/eia63m
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics