# re: [討論] hibernate Annotation 自動(dòng)生成數(shù)據(jù)庫
2007-03-23 10:51 |
hibernate Annotation不用SchemaExport也可以生成表呀,只要在sessionFactory配置的過程中
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
其中update表示加載hibernate自動(dòng)更新數(shù)據(jù)庫結(jié)構(gòu),你也可以用create,但這樣你數(shù)據(jù)庫中的所有數(shù)據(jù)都會(huì)被清除,估計(jì)你現(xiàn)在寫的是none,所以不會(huì)自動(dòng)生成
回復(fù) 更多評(píng)論
# re: [討論] hibernate Annotation 自動(dòng)生成數(shù)據(jù)庫
2007-03-25 01:43 |
謝謝 各位的熱情討論 , 搞定了
只要在 sessionFactory 中的 property 設(shè)置一個(gè) hibernateProperties 屬性 添加
<prop key="hibernate.hbm2ddl.auto">update</prop>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="annotatedClasses">
<list>
<value>com.shuttle.test.AnnotationsTest</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
回復(fù) 更多評(píng)論