日期:2014-05-20  浏览次数:20906 次

Spring集成Hibernate无法创建数据库表?
我在用Spring集成Hibernate时,配置好了Hibernate.cfg.xml和applicationContext.xml都没用问题,但是在Tomcat启动的时候,无法创建数据库,这些Tomcat启动时的提示信息。我的OpenSessionInViewFilter等都配好了,经过之前的测试,都成功了,目前最怀疑的就是User.hbm.xml文件配置。其实,我的多个数据库表均无法生成,只列出User表无法创建的信息。另外我的entity.hbm.xml和Hibernate.cfm.xml都是通过Ant+Xdoclet生成的。
错误日志信息:

**11:46:40,328 INFO DatabaseMetadata:91 - table not found: T_User
**11:46:40,515 DEBUG SchemaUpdate:149 - create table T_User (id integer not null auto_increment, username varchar(255) not null unique, password varchar(255) not null, createTime datetime, expireTime datetime, person integer unique, primary key (id))
**11:46:40,593 ERROR SchemaUpdate:155 - Unsuccessful: create table T_User (id integer not null auto_increment, username varchar(255) not null unique, password varchar(255) not null, createTime datetime, expireTime datetime, person integer unique, primary key (id))

User.hbm.xml文件的主要配置为:

<hibernate-mapping>
  <class table="T_User" name="com.shizhong.oa.model.User">
  <id name="id">
  <generator class="native"/>
  </id>
  <property name="username" not-null="true" unique="true"/>
  <property name="password" not-null="true"/>
  <property name="createTime" update="false"/>
  <property name="expireTime"/>
  <many-to-one unique="true" name="person"/>
  </class>
</hibernate-mapping>



万能的CSDN,请救救我吧,这个问题困扰了我一个上午,以前建数据库时好像与今天没有什么不同,为什么今天就不行了呢?

------解决方案--------------------
你先用spring框架在用hibernate,那个hibernate.cfg.xml不要了,只要那个applicationContext.xml配置不就行了
------解决方案--------------------
<property name="hibernate.hbm2ddl.auto">update</property>
------解决方案--------------------
hibernate.cfg.xml这个文件里的内容可以移植到applictioncontext-*.xml文件里

------解决方案--------------------
楼主可以去试试用 spring结合hibernate中的这个 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
去连接数据库
------解决方案--------------------
<property name="hibernate.hbm2ddl.auto">update </property>5楼正确
我们也在用 spring + hibernate + JSF