【问题标题】:Hibernate is not creating tables and altered automaticallyHibernate 不创建表并自动更改
【发布时间】:2020-11-16 00:04:27
【问题描述】:

尝试使用 hibernate 创建表,但它已创建并删除。

Console:

Hibernate: `create table category (catid integer not null auto_increment, catdesc varchar(255), cattitle varchar(255), primary key (catid)) type=MyISAM`
Hibernate: create table category_product (Category_catid integer not null, p_pid integer not null) type=MyISAM
Hibernate: create table product (pid integer not null auto_increment, pDesc varchar(255), pDiscount integer not null, pName varchar(255), pPhoto varchar(255), pPrice integer not null, pQuantity integer not null, c_catid integer, primary key (pid)) type=MyISAM
Hibernate: create table user (id integer not null auto_increment, address varchar(255), mail varchar(255), name varchar(255), pass varchar(255), ph_no integer not null, primary key (id)) type=MyISAM
Hibernate: alter table category_product drop index UK_52hqb12vl2fe0l0d78hk2d88h
Hibernate: alter table category_product add constraint UK_52hqb12vl2fe0l0d78hk2d88h unique (p_pid)
Hibernate: `alter table category_product add constraint FKsqii9ofndgvr0cscbvb5e4uds foreign key (p_pid) references product (pid)`
Hibernate: alter table category_product add constraint FK29xlj9k6tq2niv1udd6a1msmd foreign key (Category_catid) references category (catid)
Hibernate: alter table product add constraint FKsw4ctbskvoom8us7igpgu6fqt foreign key (c_catid) references category (catid)

hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration>
    <session-factory>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/shoppingcart?useSSL=false</property>
            <property name="hibernate.connection.username">root</property>
            <property name="hibernate.connection.password">root123</property>
            <property name="show_sql">true</property>      
            <property name="hbm2ddl.auto">update</property>
            <mapping class="com.sourav.model.User"/>     
            <mapping class="com.sourav.model.Product"/>
            <mapping class="com.sourav.model.Category"/> 
    </session-factory>
</hibernate-configuration>

模型类:

import java.util.List;

import javax.persistence.*;

@Entity
@Table(name="category")
public class Category {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int catid;
    private String cattitle;
    private String catdesc;
    @OneToMany
    private List<Product> p;
    public int getCatid() {
        return catid;
    }
    public void setCatid(int catid) {
        this.catid = catid;
    }
    public String getCattitle() {
        return cattitle;
    }
    public void setCattitle(String cattitle) {
        this.cattitle = cattitle;
    }
    public String getCatdesc() {
        return catdesc;
    }
    public void setCatdesc(String catdesc) {
        this.catdesc = catdesc;
    }
    public List<Product> getP() {
        return p;
    }
    public void setP(List<Product> p) {
        this.p = p;
    }
    public Category(String cattitle, String catdesc, List<Product> p) {
        super();
        this.cattitle = cattitle;
        this.catdesc = catdesc;
        this.p = p;
    }
    
    
}

Hibernate: 创建表类别 (catid integer not null auto_increment, catdesc varchar(255), cattitle varchar(255), primary key (catid)) type=MyISAM Hibernate:创建表 category_product (Category_catid integer not null, p_pid integer not null) type=MyISAM Hibernate:创建表产品(pid整数不为空auto_increment,pDesc varchar(255),pDiscount整数不为空,pName varchar(255),pPhoto varchar(255),pPrice整数不为空,pQuantity整数不为空,c_catid整数,主键(pid)) 类型=MyISAM Hibernate:创建表用户(id integer not null auto_increment,address varchar(255),mail varchar(255),name varchar(255),pass varchar(255),ph_no integer not null,primary key (id)) type=MyISAM 休眠:更改表类别_产品删除索引 UK_52hqb12vl2fe0l0d78hk2d88h 休眠:更改表 category_product 添加约束 UK_52hqb12vl2fe0l0d78hk2d88h 唯一(p_pid) 休眠:更改表 category_product 添加约束 FKsqii9ofndgvr0cscbvb5e4uds 外键 (p_pid) 引用产品 (pid) Hibernate:更改表 category_product 添加约束 FK29xlj9k6tq2niv1udd6a1msmd 外键(Category_catid)引用类别(catid) Hibernate:更改表产品添加约束 FKsw4ctbskvoom8us7igpgu6fqt 外键 (c_catid) 参考

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    我已经通过删除解决了这个问题

    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    

    【讨论】:

      猜你喜欢
      • 2018-11-19
      • 2017-08-23
      • 2012-07-02
      • 2018-08-18
      • 2015-06-11
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2020-03-11
      相关资源
      最近更新 更多