1. hibernate无法管理有参数的bean构造方法,必须有一个默认的构造方法
2. 每一个bean最好都有一个id,id 代表主键
3. bean类不要设置能final , 以便继承扩展
4. SessionFactory只应做一次连接资源, 所以最好做一个工具类初始化这个操作保证只执行一次.
1.hibernate必须有一个hibernate.cfg.xml 和 *.hbm.xml. hibernate.cfg.xml文件名是默认值,程序中有的方法可以指定.
e.g. Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml");
2. hibernate.cfg.xml如何配置找hibernate 3.2/etc/hibernate.properties
3.
#hibernate.hbm2ddl.auto create-drop //测试完毕把表删掉
#hibernate.hbm2ddl.auto create //创建之前把表删掉
#hibernate.hbm2ddl.auto update //不一致更新表结构
#hibernate.hbm2ddl.auto validate //较验, 不会更新表,报错. 正式环境使用的方式
4.hibernate的3种状态
瞬时, 持久,托管
瞬时--刚生成的object, 在无用的时候被垃圾回收, 跟session无关
持久---在session里, 发生状态session知道.
脱管--session已经关闭, 这个时候处于脱管, 所以它改变session无关