spring集成hibernate 怎样在控制台输出打印建表语句
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring集成hibernate 怎样在控制台输出打印建表语句相关的知识,希望对你有一定的参考价值。
楼上的方法只能打印出增删改查的语句,并不能打印出建表的语句。貌似不能,可以直接从数据库管理工具中导出语句 ,不知楼主用的什么数据库。不过这种语句是比较“官方” 效果和我们自己写的一样,但是看起来却不不好看,大写的并且和我们建表习惯不一样 参考技术A 建表语句
public class Test
/**
* @param args
*/
public static void main(String[] args)
Configuration cfg=new Configuration().configure("/applicationContext.xml");
SchemaExport export=new SchemaExport(cfg);
export.create(true,true);
文件applicationContext.xml中涵有bean与表之间的映射的XXX.hbm.xml。
希望能给你帮助 参考技术B 配置数据源那里加上<property name="show_sql">true</property> 参考技术C <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.mysqlInnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
起作用的是<prop key="hibernate.hbm2ddl.auto">update</prop>这一句,自动建表
追问
create 这个设置是可以自动建表的,可是建表语句在控制台看不到,只能打印出增删改查的语句(数据库是:MySQL)。
ssh(struts,spring,hibernate)开发的初步集成01--依赖
一.概念
SSH 通常指的是 Struts2 做前端控制器,spring 管理各层的组件,hibernate 负责持久化层。
SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,MyBatis 负责持久化层。
二.构建流程
创建maven工程...在pom.xml文件中配置需要的依赖
<properties>
<java-version>1.8</java-version>
<junit-version>4.8.2</junit-version>
<org.springframework-version>3.2.4.RELEASE</org.springframework-version>
<jackson-mapper-asl-version>1.9.12</jackson-mapper-asl-version>
<jackson-core-asl-version>1.9.12</jackson-core-asl-version>
<mysql-connector-java-version>5.1.8</mysql-connector-java-version>
<org.mybatis-version>3.2.7</org.mybatis-version>
<org.mybatis-spring-version>1.2.2</org.mybatis-spring-version>
<opensymphony-version>2.4.2</opensymphony-version>
<freemarker-version>2.3.9</freemarker-version>
<c3p0-version>0.9.1.2</c3p0-version>
<commons-collections-version>1.0</commons-collections-version>
<commons-fileupload-version>1.2.2</commons-fileupload-version>
<org.apache.commons-version>3.1</org.apache.commons-version>
<commons-codec-version>1.6</commons-codec-version>
<dom4j-version>1.6.1</dom4j-version>
<javax.servlet-version>1.2</javax.servlet-version>
<aspectjweaver-version>1.6.6</aspectjweaver-version>
<slf4j-log4j12-version>1.6.6</slf4j-log4j12-version>
<log4j-version>1.2.16</log4j-version>
<javax.servlet-jsp-version>2.0</javax.servlet-jsp-version>
<cglib-version>2.2.2</cglib-version>
<slf4j-api-version>1.6.6</slf4j-api-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- with junit4.8.2 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<type>jar</type>
</dependency>
<!-- with spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument-tomcat</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!--springmvc 杞?Json -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${jackson-mapper-asl-version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>${jackson-core-asl-version}</version>
</dependency>
<!--freemarker -->
<dependency>
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker-version}</version>
</dependency>
<!-- with mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${org.mybatis-version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>${org.mybatis-spring-version}</version>
</dependency>
<!-- jdbc driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java-version}</version>
</dependency>
<!-- connect pool with c3p0 -->
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>${c3p0-version}</version>
</dependency>
<!-- apache commons jar -->
<!-- <dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>${commons-collections-version}</version>
<scope>provided</scope>
</dependency> -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload-version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${org.apache.commons-version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec-version}</version>
</dependency>
<!-- analyze xml use dom4j -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>${dom4j-version}</version>
</dependency>
<!-- about servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${javax.servlet-version}</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<!-- memcached -->
<dependency>
<groupId>com.google.code.maven-play-plugin.spy</groupId>
<artifactId>memcached</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib-version}</version>
</dependency>
<dependency>
<groupId>net.fckeditor</groupId>
<artifactId>java-core</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
</dependency>
<!-- excel鎿嶄綔 -->
<!-- <dependency> <groupId>cn.liu.jxl</groupId> <artifactId>jxl</artifactId>
<version>2.6.10</version> </dependency> -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>jsptags</groupId>
<artifactId>pager-taglib</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.10</version>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>oscache</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.8</version>
<exclusions>
<exclusion>
<artifactId>javassist</artifactId>
<groupId>javassist</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.1.7.Final</version>
</dependency>
<dependency>
<groupId>displaytag</groupId>
<artifactId>displaytag</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<finalName>ssh</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<!-- <path>/</path> -->
<username>admin</username>
<password>123</password>
</configuration>
</plugin>
</plugins>
</build>
</project>
以上皆为ssh项目的依赖..大家也可以根据自己的需求添加
以上是关于spring集成hibernate 怎样在控制台输出打印建表语句的主要内容,如果未能解决你的问题,请参考以下文章
Spring Security 3 身份验证与 Hibernate 3(JPA) 注释的集成
ssh(struts,spring,hibernate)开发的初步集成01--依赖
用Jersey构建RESTful服务7--Jersey+SQLServer+Hibernate4.3+Spring3.2