I have created one entity class Emp, I am using hbm2ddl.auto to create tables, below entity related table is creating properly, but before this table in my database some more tables are there, if i use property hbm2ddl.auto as create it need to drop the total schema(total tables) and created the entity related table freshly, old tables are not deleted. That tables are there and this new table is created, I am not getting this create functionality can anyone please clarify my doubt. I used the version 3.6.4.
Emp.java =============== @Entity @Table(name="Employe") public class Emp { @Id int empid; String ename;
public int getEmpid() { return empid; }
public void setEmpid(int empid) { this.empid = empid; }
public String getEname() { return ename; }
public void setEname(String ename) { this.ename = ename; } }
configuration.cfg.xml ==================
<hibernate-configuration> <session-factory> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/sample</property> <property name="connection.username">root</property> <property name="connection.password">sun</property> <property name="connection.pool_size">1</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="show_sql">true</property> <property name="hbm2ddl.auto">create</property> <mapping class="in.hib.Emp" /> </session-factory> </hibernate-configuration>
My main program is this
public class HibApplication {
public static void main(String[] args) { Emp e=new Emp(); e.setEmpid(2); e.setEname("pavai"); Configuration cfg=new Configuration().configure(); SessionFactory sf=cfg.buildSessionFactory(); Session session=sf.openSession(); session.beginTransaction(); session.save(e); session.getTransaction().commit(); } }
|