请问:
        session.beginTransaction();        Event theEvent = new Event();
        theEvent.setTitle(title);
        theEvent.setDate(theDate);        session.save(theEvent);        session.getTransaction().commit();问题:
session保存theEvent对象的时候,是将保存的sql语句放在哪儿,Transaction对象是如何获取这个sql语
句的呢,我想了解Hibernate的处理机制谢谢

解决方案 »

  1.   

    可以参考 
    http://www.javaeye.com/topic/186068
      

  2.   

    找个hibernate的帮助文档学习下吧
    http://download.csdn.net/source/500442
      

  3.   

    hibernate.cfg.xml如列子中加红色的部分在控制太能看到sql语句
    <?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>
    <property name="connection.driver_class">
    com.mysql.jdbc.Driver
    </property>
    <property name="myeclipse.connection.profile">mysql</property>
    <property name="connection.url">
    jdbc:mysql://127.0.0.1:3306/test
    </property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>
    <property name="dialect">
    org.hibernate.dialect.MySQLDialect
    </property>
    <property name="show_sql">true</property> <property name="hbm2ddl.auto">update</property>
    <mapping resource="com/tarena/zsk/domain/User.hbm.xml" />
    </session-factory>
    </hibernate-configuration>
      

  4.   

    <property name="show_sql">true </property>要配置这句了
    才在控制台下看得到sql语句
      

  5.   

    session.save(theEvent); --当前数据保存到session中,也就是一级缓存中        session.getTransaction().commit(); --通知session把当前数据同步提交到数据库
      

  6.   

    哈哈,你问的是Hibernate如何实现的吧,去看他源码最清楚了,他底层就是自己拼接SQL啊,没有什么特别的秘密啊,比如你调用 save方法,Hibernate判断下,你DB有资料,那就根据你 的 Model.hbm.xml里面的属性和对应的SQL列,拼接Insernt语句啊。 你 Model.hbm.xml 不是有Model属性和数据库表的列做了对应吗,他就是根据这个拼接SQL的。
      

  7.   

    http://topic.csdn.net/u/20091111/09/d6806c0e-5afa-4124-948b-66240e8bfe8a.html
    这个帖也是你发的吧?
    一看就知道你对那个帖的回复还没理解
      

  8.   

    相当于自己去写的ORM,拼凑SQL语句 
      

  9.   

    通过反射机制 把实体类对应的ORM映射文件字段赋值.而赋值后的orm字段 就是我们常写的sql.
    hibernate:把面向过程转为面向对象.在处理数据库的时候,又把面向对象转为面向过程.