趣味によっては、XML設定またはJava設定でSessionFactory
を作成している可能性があります。 SessionFactory
をリポジトリBeanに注入して使用するだけです。休止状態にある `HibernateDaoSupport`がありません
@Repository
public class SomeEntityRepository {
private SessionFactory sessionFactory;
// Constructor-injection injects a SessionFactory
@Autowired
public SomeEntityRepository(SessionFactory sessionFactory) {
this.sesssionFactory = sessionFactory;
}
// uses SessionFactory to get the current session, iterates the collection
// and calls saveOrUpdate on each instance inside the collection.
public void saveOrUpdateAll(Collection<?> collection) {
Session session = sessionFactory.getCurrentSession();
for(Object object : collection) {
session.saveOrUpdate(object);
}
}
}
:よう
単純な例では見ることができます。それは常に春に存在します。 –
@ v.ladynevはい、私は今質問を解決しています – blackdog
は、コレクションを通じて、すべての要素でsaveOrUpdate()を呼び出します。何が難しいですか? –