重複している場合は、申し訳ありません。私の質問に対する答えが見つかりませんでした。
休止状態を開始したところです。プログラムが実行中に古いshcemeを自動的に削除し、新しいshcemeを作成するたびに問題があります。たとえば、データベースにレコードを追加したい場合、スキームが再作成され、履歴が削除されるため、できませんでした。
これが私のhbm.xmlマッピング ファイルです。
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 22-Oct-2013 1:39:31 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="net.ys.hibernate.Equip" table="EQUIP">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="dis" type="java.lang.String" column="dis" />
<property name="ref" type="java.lang.String" column="ref" />
<property name="type" type="java.lang.String" column="type" />
</class>
</hibernate-mapping>
hibernate.cfg.xml 構成ファイル。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- hibernate dialect -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">pw</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/explorer_DB?useUnicode=true&characterEncoding=GBK</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.default_schema">explorer_DB</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Automatic schema creation(begin) -->
<property name="hibernate.hbm2ddl.auto">create</property>
<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- mapping files with external dependencies -->
<mapping resource="net/ys/hibernate/Equip.hbm.xml"/>
</session-factory>
</hibernate-configuration>
そして addEquip メソッド:
public Integer addEquip(String dis, String ref, String type){
Session session = sessionFactory.openSession();
currentSession = sessionFactory.getCurrentSession();
Transaction tx = null;
Integer equipID = null;
try {
tx = currentSession.beginTransaction(); //start a transaction
Equip equip = new Equip(dis,ref,type);
equipID = (Integer)currentSession.save(equip);
tx.commit();
} catch (HibernateException e) {
if(tx!=null) tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
return equipID;
}
}
誰かがこの問題を解決するのを手伝ってくれますか? getCurrentSession() の使用方法がわかりません。おそらく、この点で間違っています。getCurrentSession() を呼び出すと、休止状態がどのように機能するか説明していただけますか? ほんとうにありがとう。
どうもありがとう