hibernate不能将实体类在mysql中生产相对应的表
配置:<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url"
value="jdbc:mysql://localhost/fc"></property>
<property name="username" value="root"></property>
<property name="password" value="sa"></property>
<property name="maxActive" value="5"></property>
<property name="maxIdle" value="2"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>fc.po.*</value>
</list>
</property>
</bean>实体类的超类@SuppressWarnings("serial")
@MappedSuperclass
public abstract class PoAbs implements Serializable{
private String dataId;
private String createTime;
private String creater;
private String updateTime;
private String updater;
@Id
@Column(name = "data_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
public String getDataId() {
return dataId;
}
public void setDataId(String dataId) {
this.dataId = dataId;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getCreater() {
return creater;
}
public void setCreater(String creater) {
this.creater = creater;
}


public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getUpdater() {
return updater;
}
public void setUpdater(String updater) {
this.updater = updater;
}

}实体类:@Entity
@Table(name="community")public class Community extends PoAbs { 
private String communtiyName;
private String address;
private District district;

public String getCommuntiyName() {
return communtiyName;
}
public void setCommuntiyName(String communtiyName) {
this.communtiyName = communtiyName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@ManyToOne(fetch=FetchType.LAZY)
public District getDistrict() {
return district;
}
public void setDistrict(District district) {
this.district = district;
}

}

解决方案 »

  1.   

    补充一下 实体类Community是在fc.po包下
      

  2.   

    实体类里面忘记写hibernate创建类的数据库的类型了
      

  3.   

    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <!-- <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> -->
    <prop key="hibernate.dialect">
    org.hibernate.dialect.Oracle9Dialect
    </prop>
    <!-- 创建数据库
    <prop key="hibernate.hbm2ddl.auto">create</prop>
    -->
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <!-- ===============================hibernate映射文件======================================= --> <property name="mappingDirectoryLocations">
    <list>
    <value>classpath:/com/shining/po/hbm</value>
    </list>
    </property>
    </bean>
      

  4.   

    实体类里还要指定数据库类型 怎么指定?不是在spring的配置文件里已经指定数据库类型来了吗
      

  5.   

    我用全注解方式的  不需要hbm文件映射的
      

  6.   


    你的实体类并没有注解你的字段类型呀 @Temporal(TemporalType.TIMESTAMP)
        @Column(name="UPDATE_DATE", length=11)
        public Date getUpdateDate() {
            return this.updateDate;
        }@Column(name="WL_MOBILE", length=11)
        public String getWlMobile() {
            return this.wlMobile;
        }
      

  7.   

    console控制台没有报任何错误吗?
      

  8.   

    HIBERNATE好像没有自动去创建表吧,需要你自己去写一个工具类,将这些对象导入到数据库中去的呢?
                     //读取hibernate.cfg.xml文件
    Configuration cfg = new Configuration().configure();

    SchemaExport export = new SchemaExport(cfg);

    export.create(true, true);
      

  9.   

    我就一直怀疑是那些实体类没有被扫描到  结果 我把
       <property name="packagesToScan">
                <list>
                    <value>fc.po.*</value>
                </list>
            </property>
       改成
       <property name="packagesToScan">
                <list>
                    <value>fc.*</value>
                </list>
            </property>
    就生成出来了     原来packagesToScan是扫描*前面的一个包的所有子包里面的实体类 而我po包下已经没有包了直接是实体类  所以没被扫描到