java - auto database creation in hibernate with mysql -


this code, done mistake. while running test.java getting error "the requested resource not available". kept files in same package

hibernate.cfg.xml

<hibernate-configuration>    <session-factory>     <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property>      <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/studentdb </property>     <property name="hibernate.connection.username">root</property>    <property name="hibernate.connection.password">root</property>  <property name="connection.pool_size"> 1</property>      <property name="hibernate.dialect">org.hibernate.dialect.mysqldialect</property>   <property name="hbm2ddl.auto">create</property>   <property name="show_sql">true</property>      <!-- list of xml mapping files -->    <mapping resource="student.hbm.xml"/>     </session-factory> </hibernate-configuration> 

test.java

public class test {      public static void main(string[] args) {         configuration cfg=new configuration();         cfg.configure("hibernate.cfg.xml");         cfg.buildsessionfactory();     }  } 

student.hbm.xml

<hibernate-mapping> <class name="com.javathub.student" table="stu_details"> <id name="id"> <generator class="assigned"></generator> </id> <property name="name"></property> <property name="branch"></property> <property name="fee"></property> </class>   </hibernate-mapping> 

student.java

public class student {     private int id;     private string name;     private string branch;     private double fee;     public student(){      }     public student(int id, string name, string branch, double fee) {         super();         this.id = id;         this.name = name;         this.branch = branch;         this.fee = fee;     }     public int getid() {         return id;     }     public void setid(int id) {         this.id = id;     }     public string getname() {         return name;     }     public void setname(string name) {         this.name = name;     }     public string getbranch() {         return branch;     }     public void setbranch(string branch) {         this.branch = branch;     }     public double getfee() {         return fee;     }     public void setfee(double fee) {         this.fee = fee;     }  } 

please me, in advance

keep student.hbm.xml , hibernate.cfg.xml in src folder not in package , run again.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -