user13396239
user13396239

Reputation:

Hibernate is not creating tables and altered automatically

Trying to create tables with hibernate but it's created and dropped.

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>

Model class:

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: 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) referenc

Upvotes: 2

Views: 106

Answers (1)

user13396239
user13396239

Reputation:

I have solved this by removing

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

Upvotes: 0

Related Questions