0
我的web項目spring spring-mvc和hibernate,當tomcat啓動的時候沒有在mysql db中創建表。爲什麼?並沒有錯誤信息當實體註釋時Hibernate不能創建表?
SessionFactory的
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.woodcoder.bean</value>
</list>
</property>
</bean>
屬性
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=false
,我試圖hibernate.hbm2ddl.auto=create
,這是相同的。 爲什麼hibernate不創建表?
實體
@Entity
@Table(name="user_bean")
public class UserBean extends BaseBean {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
的baseEntity
@MappedSuperclass
public class BaseBean implements Serializable{
/**
* ID
*/
@Id
@Column(name="id",length = 32, nullable = true)
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid")
private String id;
@Column(updatable = false)
private Date createDate;
private Date modifyDate;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
打開調試日誌記錄(如果沒有)。也許模式工具發現錯誤,但由於日誌級別較低,您沒有看到它們。其次,確保您的XML文件正在被部署戰中的值正確替換。這通常可能是事情沒有發生的原因。 – Naros
作爲你的建議,我降低日誌級別DEBUG,然後我得到更多的信息,但沒有創建表。我檢查了tomcat中的deploy目錄,所有的屬性和xml文件都已經正確部署。 –