27. insert Department dep = new Department(); dep.setName(“ 软件开发部” ); Session s = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); s.save(dep); tx.commit(); s.close();
28. Load Session s = sessionFactory.openSession(); Department dep = (Department)s.get(Department.class, depID); s.close();
29. update Session s = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); Department dep = (Department)s.get(Department.class, depID); dep.setName("ggggg"); s.update(dep); tx.commit(); s.close();
30. delete Session s = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); Department dep = (Department)s.get(Department.class, depID); s.delete(dep); tx.commit(); s.close();
31. 使用 Ant 构建开发过程 Another Neat Tool 另一个整洁的工具。 ANT 是一个基于 Java 的自动化脚本引擎,脚本格式为 XML 。 每个 ant 脚本(缺省叫 build.xml )中设置了一系列任务 (target) ,而多个任务之间往往又包含了一定的依赖关系。 Ant 可以简化项目的编译、测试、文档、部署等日常工作的手工工作量。
48. Table per class hierarchy 整个继承树对应一张表,子类用 type discriminator 字段来区分。这种方式在性能和简单性两方面都做的很好。 父类的变动很方便。
49. 多态查询 查询父类 select BILLING_DETAILS_ID, BILLING_DETAILS_TYPE,OWNER, ..., CREDIT_CARD_TYPE, from BILLING_DETAILS where CREATED = ? 查询子类 select BILLING_DETAILS_ID,CREDIT_CARD_TYPE,CREDIT_CARD_EXP_MONTH, ...from BILLING_DETAILS where BILLING_DETAILS_TYPE='CC' and CREATED = ? problem :子类属性对应的 column 不可以有 not null 的约束。
84. 优化设计后的代码 User user = new User(); user.setName(name); user.setPassword(password); user.setEmail(email); PersistenceFactory.getInstance().makePersistent(user);
85. 沉重的反思——事务脚本 粒度顺序是: service > dao > domain 业务逻辑尽量写在 domain 里,不要在 service 写任何业务逻辑,而仅仅在 service 里调用 dao 和 domain ,完成事务逻辑,供前台调用。
86. 参考书籍 Hibernate In Action——CHRISTIAN BAUER 、 GAVIN KING Patterns of Enterprise Application Architecture ( 企业应用架构模式 )——Martin Fowle 深入浅出 Hibernate—— 夏昕、曹晓钢