迁移到 ORM
逐步来说,将 Spring 和 Hibernate 集成到不使用 ORM 的现有 JSF 应用程序中的好方法是什么?
Stepwise, what would be a good way of integrating Spring and Hibernate into an existing JSF application that doesn't use ORM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1)您需要先设计领域模型,然后将其映射到数据库。您可以使用 hibernate 逆向工程工具来实现此目的。
2)其他选项是将当前对象(DTO)手动映射到数据库表。由于您使用 JSF,我假设您当前拥有一些对象。
3) 围绕对象设计服务层。
春天 -
1) 可以使用Spring提供hibernate模板,通过bean提供常用服务。
2)您可以在Spring中管理事务。
1) You would need to design the domain model first and then map it to the database. You could use hibernate reverse engineering tools for this.
2) Other option is to manually map your current objects(DTO) to database tables. Since you use JSF, I assume you'd be having some objects currently.
3) Design the Service Layer around the objects.
Spring -
1) You could use Spring to provide hibernate template, provide common services through bean.
2) You can manage the transaction in Spring.
如果您认真对待 ORM,请查看 Christian Bauer 的 Java Persistence With Hibernate(Manning 出版社),这是关于 Java 上的 hibernate 和 JPA 的“圣经”。
If you're serious about ORM, please look at Java Persistence With Hibernate of Christian Bauer (Manning publications), this is "the bible" about hibernate and JPA on Java.
如果您正确编写了 Spring,您应该拥有 DAO/存储库接口。如果是这种情况,您所要做的就是使用 Hibernate 编写该接口的新实现,对其进行测试,然后更改 Spring 配置以注入它。
ORM 假定您有一个对象模型可以映射到关系模式。如果你不这样做,我建议你不要使用 ORM。在这种情况下,最好使用 iBatis 或 JDBC。
If you've written Spring properly, you should have DAO/repository interfaces. If that's the case, all you have to do is write a new implementation of that interface using Hibernate, test it, and change your Spring configuration to inject it.
ORM presumes that you have an object model in place to map to a relational schema. If you don't, I would advise against using ORM. Better to use iBatis or JDBC in that case.