【问题标题】:How to Design and Architect a Hibernate Application如何设计和构建 Hibernate 应用程序
【发布时间】:2015-01-07 16:46:30
【问题描述】:

我是 hibernate 新手,我学习了如何使用 Hibernate 注释创建实体和映射所有实体。我已使用以下代码配置设置来创建表并将数据保存到数据库中,并在 Hibernate 配置设置中使用 JDBC 方法。

  Configuration configuration = new Configuration();
  configuration.configure();

  ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().
                                    applySettings(configuration.getProperties()).build();

  SessionFactory sessionFactory = 
                            configuration.buildSessionFactory(serviceRegistry);

  Session session = sessionFactory.openSession();

  session.beginTransaction();

  /******************
         In between I have used the code
         for Loading and Saving the data
  *******************/ 

  session.getTransaction().commit();

  session.close();

  sessionFactory.close();

我看到了其他使用持久性配置的示例。

之前当我们使用 JDBC 应用程序时,我们会创建一个单独的连接类和单独的类来处理 prepareStatement 或 Statement 类,并且还会尝试管理事务。

有人可以帮助我如何为 Hibernate 类型的项目做出最佳设计。

【问题讨论】:

  • 可以使用spring框架。

标签: hibernate architecture


【解决方案1】:

这是一个非常广泛的问题。反正我会回答的。

我使用 Spring 来实现依赖注入和 AOP 事务优势。

很多人通常使用下面示例链接中提到的 SpringMVC 和 Hibernate。事实证明它非常好。

http://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial

【讨论】:

  • 感谢 Zeus 提供的好教程,如果我们使用的是 spring,这将是适用的。如果我们使用的不是 spring,我们如何处理这个架构。
猜你喜欢
  • 2015-11-15
  • 2016-02-21
  • 1970-01-01
  • 2019-10-15
  • 2015-02-08
  • 2010-10-06
  • 2011-06-28
  • 2022-11-03
  • 2015-11-19
相关资源
最近更新 更多