首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

hibernate 课程

2012-10-25 
hibernate 教程原理:http://wenku.baidu.com/view/3f2848eef8c75fbfc77db231.html??实践:结合两个例子实践

hibernate 教程

原理:

http://wenku.baidu.com/view/3f2848eef8c75fbfc77db231.html

?

?

实践:

结合两个例子实践:

?

http://developer.51cto.com/art/200906/126554.htm

http://wenku.baidu.com/view/3182112acfc789eb172dc886.html

?

出的问题:

a.

(转自他人的)

    这个时候得看其他的方面。我出现的问题是

    ?

      在这里没有写

      ?

        ?添加这句话之后程序OK.

        ?

        ?

        ?new Configuration()默认是读取hibernate.properties

        ?所以使用new Configuration().configure()来读取hibernate.cfg.xml文件

        ?

        ?

        ?

        ?

        ?

        ?

        b.

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

        ?

        c.

        <hibernate-configuration>

        ??? <session-factory>
        ??? ??? <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        ??????? <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
        ?????? ??? <property name="hibernate.connection.username">root</property>
        ?? ??? ??? ?<property name="hibernate.connection.password">1234</property>
        ??????? <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        ??????? <property name="show_sql">true</property>
        ??????? <mapping resource="com/wshiw/model/User.hbm.xml" />
        ??? </session-factory>

        </hibernate-configuration>

        <hibernate-mapping>
        ??? <class name="com.wshiw.model.User" table="user">
        ??? ??? <id name="id" type="java.lang.Integer">
        ??? ??? ??? <column name="id" />
        ??? ??? ??? <generator />
        ??? ??? </id>
        ??? ??? <property name="name" column="name" type="java.lang.String" >
        ??? ??? </property>
        ??? ??? <property name="age"? column="age" type="java.lang.Integer" >
        ??? ??? </property>
        ??? </class>
        </hibernate-mapping>

        ?

        ?

        ?

        d.

        Query query = session.createQuery("from User where username = ? and password = ?");

        注意User是大写开头的,就对象而不是表名。

        ?

热点排行