7月27日学習日誌

2871 ワード

前に述べたように、プロジェクトにはspringから提供されたOpenSession InViewFilterが使われています.このフィルターを使ってから、荷重を遅くするのが効果的です.添加も便利です.しかし更新と削除はもう有効ではないです.何の間違いも報告していません....おかしいですね.DAO層のコードはこう書きます.
 
public void deleteEmployee(Employee employee) {
		this.getHibernateTemplate().delete(employee);
		
	}

public void updateEmployee(Employee employee) {
		this.getHibernateTemplate().update(employee);
		
	}
 
 この二つの方法は実行されていません.(コンソールは削除または更新された文を印刷していません.)その後、他の方法を試してみましたが、こんなに効果的なのです.
 
public void deleteEmployee(Employee employee) {
		this.getHibernateTemplate().delete(employee);
		this.getSession().delete(employee);
		this.getSession().beginTransaction().commit();
		
	}
 
 事務の問題ですか?しかし、フィルターを作る時に自動提出を設置しました.
<filter>
	<filter-name>openSessionInviewFilter </filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
    <init-param>  
  	<param-name>flushMode</param-name>  
  	<param-value>AUTO</param-value>  
  	</init-param>
    </filter>
   今まで私もよく分かりませんでした.解答を求めます....
  その後、事務を勉強して、このように書いてもいいです.
 
@Transactional(isolation=Isolation.READ_COMMITTED,propagation=Propagation.REQUIRED,readOnly=false,timeout=60,rollbackFor=Exception.class)
	public void deleteEmployee(Employee employee) {
		this.getHibernateTemplate().delete(employee);
		
		
	}
 
 また、setを並べ替えたいですが、調べたら2つの方法があります.
最初の方法は、プロファイルを変更して、order-byを指定します.ノート:datetimeは属性名ではなく表のフィールド名です.
 
<set name="comments" inverse="true" order-by="datetime desc">
            <key>
                <column name="articleId" />
            </key>
            <one-to-many class="com.teamlab.entity.Comment" />
        </set>
 
 もう一つの方法は、sortを使ってsetを並べ替えることです.
 
<set name="comments" inverse="true" sort="com.teamlab.entity.Comment " >
            <key>
                <column name="articleId" />
            </key>
            <one-to-many class="com.teamlab.entity.Comment" />
        </set>
 
Artcleエンティティ類では、hashSetをTreeSetに変更します.
 
 
//private Set comments = new HashSet(0);
private Set comments = new TreeSet(0);
  また、Comments類はCompratorインターフェースを実現します.第一の方法を使いましたが、第二の方法は使いませんでした.どれが効率がいいか分かりません.解を求める
もう一つのことは不明ですが、HashSetのは順序が保証されていないのではないですか?でも、どうして並べ替えがいいですか?.....