实体层
@Entity
public class Teacher { @Id
@GeneratedValue
private int id;

@Column(nullable = false,length = 20)
private String name;

@Column(nullable = false,length = 20 )
private String pwd; 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;
} public String getPwd() {
return pwd;
} public Teacher(int id, String name, String pwd) {
super();
this.id = id;
this.name = name;
this.pwd = pwd;
} public Teacher() {
super();
} public void setPwd(String pwd) {
this.pwd = pwd;
}
}
spring 生成数据表的配置如下
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="annotatedClasses">
<list>
<value>com.school.pojo.Students</value>
<value>com.school.pojo.Teacher</value>
</list>
</property>这个也写了      hibernate.hbm2ddl.auto=create
服务器启动后没报什么错,但是数据库就是没有生成任何表,这是怎么回事?

解决方案 »

  1.   


    你哪里写了? 我没看见啊。<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan">
    <list>
    <value>xxx.domain</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    </props>
    </property>
    </bean>
    一般是写在SessionFactory的配置里吧。
      

  2.   

    <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
      

  3.   

    需要写测试类啊哥
    @Test
    public void testSchemaExport() {
    new SchemaExport(new AnnotationConfiguration().configure()).create(
    true, true);
    }
    跑一下这个方法就可以了
      

  4.   

    可以了,谢谢各位.是包名自动补全导错了,郁闷!是这个包名import javax.persistence.Entity;