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;
}
}
配置:<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;
}
}
解决方案 »
- 请教下AJAX删除记录的问题
- 关于JSP页面的显示问题(如果二个不同身份的人进入同一页面显示不同的个人信息)~~急求
- 如何记录jsp被浏览的次数
- 关于struts1 html:multibox 的一个问题
- 使用hibernate 还是 ibatis
- jsp与数据库的问题?
- servlet中如何获得/WEB-INF/conf这个实际路径
- 来帮我看看这个html:options的小程序怎么老是出错,在线等,
- 字符串"***/***" 怎么取得"/"后的子字符串啊?
- JSP里exit怎么写(PHP里的exit功能)?
- 求各位大侠帮忙 java导出为html文件 excel相关
- hibernate的实体类属性注解问题
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>
你的实体类并没有注解你的字段类型呀 @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;
}
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
<property name="packagesToScan">
<list>
<value>fc.po.*</value>
</list>
</property>
改成
<property name="packagesToScan">
<list>
<value>fc.*</value>
</list>
</property>
就生成出来了 原来packagesToScan是扫描*前面的一个包的所有子包里面的实体类 而我po包下已经没有包了直接是实体类 所以没被扫描到