只用hibernate的时候可以用new SchemaExport(new Configuration().configure()).create(true, true);方式
但是现在整合了spring之后,没有了hibernate.cfg.xml文件
原本都内容都放到了beans.xml中,以及采用hibernate加注解的方式实现
也就没有了new Configuration().configure()
网上有个帖子说是配置在beans.xml中的sessionFactory继承自某个类,然后那个类有getConfigure()方法
于是可以用SchemaExport的方式在控制台上输出建表语句
但是我在用的时候发现那些方法都是protected的 不可以被访问
不知道有没有同学遇到我这个需求,然后都是怎么解决的?
------解决方案--------------------------------------------------------
个人建议,hibernate的配置文件最好从spring里提出来,这样方便管理
------解决方案--------------------------------------------------------
show_sql设置为true
------解决方案--------------------------------------------------------
显示sql语句show_sql 为true
格式化sql语句hibernate.format_sql 为true
hibernate.order_updates 为true
------解决方案--------------------------------------------------------
显示sql语句show_sql 为true
设置hibernate.format_sql 为true
设置hibernate.order_updates 为true
------解决方案--------------------------------------------------------
如果你用hibernat,
- Java code
<!-- Hibernate Session Factory --> - <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">- <property name="dataSource"> <ref bean="dataSource" /> </property>- <property name="hibernateProperties">- <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> </props> </property>- <!-- Spring機制,掃描<value>中 所有package. --> - <property name="packagesToScan">- <list> <value>com.cybersoft4u.xian.dmo.common</value> <value>com.cybersoft4u.xian.dmo.privilege</value> <value>com.cybersoft4u.xian.dmo.hr</value> <value>com.cybersoft4u.xian.dmo.device</value> </list> </property> </bean>
------解决方案--------------------------------------------------------
- XML code
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> </props> </property><property name="packagesToScan"> <list> <value>com.cybersoft4u.xian.dmo.common</value> <value>com.cybersoft4u.xian.dmo.privilege</value> <value>com.cybersoft4u.xian.dmo.hr</value> <value>com.cybersoft4u.xian.dmo.device</value> </list> </property> </bean>