用户登录
用户注册

分享至

spring集成hibernate建表

  • 作者: 记忆改变了时间
  • 来源: 51数据库
  • 2021-01-18
楼上的方法只能打印出增删改查的语句,并不能打印出建表的语句。
貌似不能,可以直接从数据库管理工具中导出语句 ,不知楼主用的什么数据库。不过这种语句是比较“官方” 效果和我们自己写的一样,但是看起来却不不好看,大写的并且和我们建表习惯不一样



  建表语句
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。
希望能给你帮助



  


org.hibernate.dialect.MySQLInnoDBDialect
true
true
update



起作用的是update这一句,自动建表



  
<bean id="mysessionfactory" class="com.networkbench.base.database.dao.hibernate3.unclocalsessionfactorybean">
<property name="datasource"><ref local="mydatasource"/></property>
<property name="hibernateproperties">


<props>
<prop key="hibernate.dialect">org.hibernate.dialect.mysql5dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
</bean>
软件
前端设计
程序设计
Java相关