简体   繁体   中英

how can I update a table in hibernate?

I am going to start hibernate so I download a dummy code from net my problem is wherever i am running this code each time its creating a new table my data is not updating in current table please help me..

<?xml version='1.0' encoding='UTF-8'?>
 <!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

 <hibernate-mapping>
  <class name="com.javatpoint.mypackage.Employee" table="emp1000">
    <id name="id">
   <generator class="assigned"></generator>
   </id>

   <property name="firstName"></property>
   <property name="lastName"></property>

<hibernate-configuration>

   <session-factory>
       <property name="hbm2ddl.auto">create</property>
      <property     name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
    <property name="connection.username">system</property>
    <property name="connection.password">oracle</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<mapping resource="employee.hbm.xml"/>
</session-factory>

your hibernate xml is configure to create a new relation each time.

 <session-factory>
    <property name="hbm2ddl.auto">update</property>
    <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
    <property name="connection.username">system</property>
    <property name="connection.password">oracle</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
 </session-factory>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM