hibernate spring annotation setup

简介:
  1. First step setup for the pom.xml with hibernate dependency ,

hibernate dependency need to before the struts2,because the javassist dependency

 
  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>RELEASE</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>${servlet.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>${servlet.jsp.version}</version>
      <type>jar</type>
      <scope>test</scope>
    </dependency>
 
    <!-- log4j dependency -->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>${log4j.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
 
    <!-- hibernate5 -->
    <!-- hibernate 5 dependencies -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernate.version}</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.transaction</groupId>
      <artifactId>jboss-transaction-api_1.2_spec</artifactId>
      <version>${jboss.api.version}</version>
    </dependency>
 
    <!-- Spring framework -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>${spring.dbcp.version}</version>
    </dependency>
    <dependency>
      <groupId>xml-apis</groupId>
      <artifactId>xml-apis</artifactId>
      <version>${spring.xmapis.version}</version>
    </dependency>
    <!-- struts2 dependency had included spring dependencies -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>${struts2.version}</version>
    </dependency>
    <!-- http://www.mkyong.com/struts2/struts-2-hello-world-annotation-example/ -->
    <!-- -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-convention-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-json-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>
    <!-- input: http://localhost:8888/Mybatis_Sample/config-browser/index.action -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-config-browser-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-junit-plugin</artifactId>
      <version>${struts2.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-spring-plugin</artifactId>
      <version>${struts2.version}</version>
    </dependency>
 
2. ApplicationContext.xml for hibernate :
 
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="${entities.path}" />
    <property name="hibernateProperties">
      <props>
        <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
        <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
      </props>
    </property>
    
  </bean>

3. Install the hibernate tool to generate the entity class automatically:

image

choose the “hibernate tool” and “hibernate maven integration” and follow the step to install it .

4.using the hibernate reverse engineering(reveng.xml) to generate the reveng.xml file

5.using the hibernate code generate tool to generate the hibernate entities

6.create a new hibernate.cfg.xml file and then create the hibernate console

7.then you can use the HQL editor and hibernate criteria editor .

image



本文转自hcy's workbench博客园博客,原文链接:http://www.cnblogs.com/alterhu/p/5097175.html,如需转载请自行联系原作者。


目录
相关文章
|
2月前
|
XML JSON Java
使用IDEA+Maven搭建整合一个Struts2+Spring4+Hibernate4项目,混合使用传统Xml与@注解,返回JSP视图或JSON数据,快来给你的SSH老项目翻新一下吧
本文介绍了如何使用IntelliJ IDEA和Maven搭建一个整合了Struts2、Spring4、Hibernate4的J2EE项目,并配置了项目目录结构、web.xml、welcome.jsp以及多个JSP页面,用于刷新和学习传统的SSH框架。
42 0
使用IDEA+Maven搭建整合一个Struts2+Spring4+Hibernate4项目,混合使用传统Xml与@注解,返回JSP视图或JSON数据,快来给你的SSH老项目翻新一下吧
|
2月前
|
Java 数据库连接 数据库
Spring Data JPA 与 Hibernate 之区别
【8月更文挑战第21天】
37 0
|
3月前
|
Java 数据库连接 数据库
如何在Spring Boot中集成Hibernate
如何在Spring Boot中集成Hibernate
|
4月前
|
前端开发 Java 关系型数据库
在Spring3 MVC中五步配置集成注解方式Hibernate3
在Spring3 MVC中五步配置集成注解方式Hibernate3
38 3
|
4月前
|
XML Java Apache
必知的技术知识:HHS整合(Struts2+Spring+Hibernate)
必知的技术知识:HHS整合(Struts2+Spring+Hibernate)
30 0
|
5月前
|
SQL Java 数据库连接
jpa、hibernate、spring-data-jpa、jdbcTemplate
jpa、hibernate、spring-data-jpa、jdbcTemplate
|
5月前
|
Java 数据库连接 Spring
spring配合hibernate报错:sessionFactory or hibernateTemplate is required
根据你的具体情况,检查上述步骤中的一个或多个,以确定为何出现“sessionFactory or hibernateTemplate is required”错误,并采取相应的措施进行修复。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
33 0
|
5月前
|
网络安全
ssh(Spring+Spring mvc+hibernate)——updateEmp.jsp
ssh(Spring+Spring mvc+hibernate)——updateEmp.jsp
|
5月前
|
网络安全
ssh(Spring+Spring mvc+hibernate)——updateDept.jsp
ssh(Spring+Spring mvc+hibernate)——updateDept.jsp
|
5月前
|
网络安全
ssh(Spring+Spring mvc+hibernate)——showEmp.jsp
ssh(Spring+Spring mvc+hibernate)——showEmp.jsp