事先还没建表,在测试save方法时能让hibernate帮我自动生成数据库表吗?@Entity
public class Category {
private int id;
private String name;
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}下面是save的测试方法,通过Service层的方法 @Test
public void testAdd() {
Category category = new Category();
category.setName("c1");
categoryService.add(category);
}连接数据库都是交给Spring容器来管理。在测试以上方法时不能自动生成数据表?
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 't_bbs.category' doesn't exist
忘写<prop key="hibernate.hbm2ddl.auto">update</prop> 了。。
现在又来异常了org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started