1
設置初始表,用於基本登錄和「記住我」。使用Spring和Hibernate創建新項目
然而,hibernate沒有根據我的註釋類創建表......我不明白爲什麼。這裏是位於/WEB-INF/
下我applicationContext.xml
相關片段:
<context:annotation-config />
<context:component-scan base-package="com.mycompany" />
<tx:annotation-driven transaction-manager="transactionManager" />
<context:property-placeholder location="file:${catalina.home}/conf/database.properties" ignore-unresolvable="true"/>
<!-- Declare a datasource that has pooling capabilities-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="${app.jdbc.driverClassName}"
p:jdbcUrl="${app.jdbc.url}"
p:user="${app.jdbc.username}"
p:password="${app.jdbc.password}"
p:acquireIncrement="5"
p:idleConnectionTestPeriod="60"
p:maxPoolSize="100"
p:maxStatements="50"
p:minPoolSize="10" />
<!-- Declare a transaction manager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
和hibernate.cfg.xml
位於/src/main/resources
下,並得到由行家複製到/WEB-INF/classe
S:
<hibernate-configuration>
<session-factory>
<!-- We're using MySQL database so the dialect needs to MySQL as well-->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- Enable this to see the SQL statements in the logs-->
<property name="show_sql">false</property>
<!-- <property name="hbm2ddl.auto">update</property> -->
<property name="hbm2ddl.auto">Create</property>
</session-factory>
</hibernate-configuration>
和我的課程如下所示:
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.Index;
@Entity
@Table(name = "office")
public class Office extends Base {..
我的應用程序開始正常,我甚至可以登錄(因爲我也有內存服務)。然而,沒有創建數據庫表(從後端訪問),並且我也創建的持久登錄不起作用,因爲相關的表沒有被創建(我實際上在嘗試註銷時出現錯誤,指出*壞的sql沒有表persistent_login存在*)。應用程序啓動時不會發生錯誤。
我錯過了什麼?
哪些休眠您使用的版本。 –
@NimChimpsky請問你的日誌文件看,當您添加'<記錄器名稱= 「org.springframework.context」>像 \t \t <電平值= 「調試」/> \t'?檢查組件掃描並查看日誌消息。 – stacker
在hbm2ddl.auto中爲'create'嘗試小c? – aishwarya