如何在hibernate中更新表?

时间:2016-04-23 10:47:52

标签: java hibernate

我要开始休眠,所以我从网上下载一个虚拟代码我的问题是无论我在哪里运行这个代码每次创建一个新表我的数据都没有在当前表中更新请帮助我..

<?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>

1 个答案:

答案 0 :(得分:0)

你的hibernate xml配置为每次创建一个新的关系。

 <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>