Hibernate环境的配置

来源:互联网 发布:淘宝的评价管理在哪 编辑:程序博客网 时间:2024/06/07 09:08
1.导入jar包
F:\下载\jar包\jar包\hibernate3.jar
F:\下载\jar包\jar包\antlr-2.7.6.jar
F:\下载\jar包\jar包\commons-collections-3.1.jar
F:\下载\jar包\jar包\dom4j-1.6.1.jar
F:\下载\jar包\jar包\javassist-3.9.0.GA.jar
F:\下载\jar包\jar包\jta-1.1.jar
F:\下载\jar包\hibernate炸包\jar包\hibernate-annotations.jar
F:\下载\jar包\hibernate炸包\jar包\hibernate-commons-annotations.jar
F:\下载\jar包\hibernate炸包\jar包\ejb3-persistence.jar
2.导入hibernate.cfg.xml
hibernate.cfg.xml的配置:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/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/hibernate</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.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 resource="events/Event.hbm.xml"/>-->
        <mapping class="com.tedu.hibernate.model.Farmer"/>
      <mapping resource="com/tedu/hibernate/model/Student.hbm.xml"/>
    </session-factory>

</hibernate-configuration>
3.hibernate.cfg.xml在映射的时候可以用xml文件也可以加注释

xml文件的配置:例如  Student.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.tedu.hibernate.model.Student" table="student">
        <id name="id"  column="id"/>
        <property name="name" column="name" />
        <property name="age" column ="age"/>
    </class>
   
</hibernate-mapping>
0 0
原创粉丝点击