如何设计和构建休眠应用程序



我是休眠新手,我学会了如何使用休眠注释创建实体和映射所有实体。我使用以下代码配置设置来创建表并将数据保存到数据库中,并使用 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来实现依赖注入和AOP交易优势。

很多人通常使用SpringMVC和Hibernate,如下面的示例链接所述。事实证明,它非常好。

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

最新更新