- Common ways to obtain HibernateTemplate
private void myMethod () {HibernateTemplate h =
SessionFactory sessionFactory;new HibernateTemplate(sessionFactory)
- Smart code suggestions by Codota
}
/** * Return the Hibernate SessionFactory used by this DAO. */ @Nullable public final SessionFactory getSessionFactory() { return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null); }
@Override public void afterPropertiesSet() { if (getSessionFactory() == null) { throw new IllegalArgumentException("Property 'sessionFactory' is required"); } }
/** * Obtain the SessionFactory for actual use. * @return the SessionFactory (never {@code null}) * @throws IllegalStateException in case of no SessionFactory set * @since 5.0 */ protected final SessionFactory obtainSessionFactory() { SessionFactory sessionFactory = getSessionFactory(); Assert.state(sessionFactory != null, "No SessionFactory set"); return sessionFactory; }
/** * Set the Hibernate SessionFactory to be used by this DAO. * Will automatically create a HibernateTemplate for the given SessionFactory. * @see #createHibernateTemplate * @see #setHibernateTemplate */ public final void setSessionFactory(SessionFactory sessionFactory) { if (this.hibernateTemplate == null || sessionFactory != this.hibernateTemplate.getSessionFactory()) { this.hibernateTemplate = createHibernateTemplate(sessionFactory); } }
/** * Obtain the SessionFactory for actual use. * @return the SessionFactory (never {@code null}) * @throws IllegalStateException in case of no SessionFactory set * @since 5.0 */ protected final SessionFactory obtainSessionFactory() { SessionFactory sessionFactory = getSessionFactory(); Assert.state(sessionFactory != null, "No SessionFactory set"); return sessionFactory; }
/** * Return the Hibernate SessionFactory used by this DAO. */ @Nullable public final SessionFactory getSessionFactory() { return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null); }
@Override public void afterPropertiesSet() { if (getSessionFactory() == null) { throw new IllegalArgumentException("Property 'sessionFactory' is required"); } }
/** * Set the Hibernate SessionFactory to be used by this DAO. * Will automatically create a HibernateTemplate for the given SessionFactory. * @see #createHibernateTemplate * @see #setHibernateTemplate */ public final void setSessionFactory(SessionFactory sessionFactory) { if (this.hibernateTemplate == null || sessionFactory != this.hibernateTemplate.getSessionFactory()) { this.hibernateTemplate = createHibernateTemplate(sessionFactory); } }
public SessionFactory getSessionFactory() { return hibernateTemplate.getSessionFactory(); }
public SessionFactory getSessionFactory() { return hibernateTemplate.getSessionFactory(); }
public SessionFactory getSessionFactory() { return hibernateTemplate.getSessionFactory(); }
/** * Return the Hibernate SessionFactory used by this DAO. */ @Nullable public final SessionFactory getSessionFactory() { return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null); }
/** * Unsupported or unused keys should be deleted. This method deletes all entries with the given key. * * @param key Key of the entries to delete. */ protected void deleteOldKeys(final String key) { final Query query = hibernateTemplate.getSessionFactory().getCurrentSession().createQuery( "delete from " + UserXmlPreferencesDO.class.getSimpleName() + " where key = '" + key + "'"); final int numberOfUpdatedEntries = query.executeUpdate(); log.info(numberOfUpdatedEntries + " '" + key + "' entries deleted."); }
/** * Set the Hibernate SessionFactory to be used by this DAO. * Will automatically create a HibernateTemplate for the given SessionFactory. * @see #createHibernateTemplate * @see #setHibernateTemplate */ public final void setSessionFactory(SessionFactory sessionFactory) { if (this.hibernateTemplate == null || sessionFactory != this.hibernateTemplate.getSessionFactory()) { this.hibernateTemplate = createHibernateTemplate(sessionFactory); } }
@Override public void run() { final Session session = applicationContext.getBean(HibernateTemplate.class).getSessionFactory().openSession(); final Set<String> alreadyReindexed = new HashSet<String>(); final List<Entry> entryList = map.get(obj.getClass()); reindexDependents(session, obj, entryList, alreadyReindexed); session.disconnect(); final int size = alreadyReindexed.size(); if (size >= 10) { log.info("Re-indexing of " + size + " objects done after updating " + obj.getClass().getName() + ":" + obj.getId()); } } }.start();
new HibernateTransactionManager(hibernate.getSessionFactory())); tx.execute(new TransactionCallback()
new HibernateTransactionManager(hibernate.getSessionFactory())); tx.execute(new TransactionCallback()
final SessionFactory sessionFactory = hibernate.getSessionFactory(); Session session = null; boolean hasError = false;
onSaveOrModify(obj); BaseDaoJpaAdapter.prepareInsert(obj); Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); Integer id = (Integer) session.save(obj); log.info("New object added (" + id + "): " + obj.toString());
final SessionFactory sessionFactory = hibernate.getSessionFactory(); session = HibernateCompatUtils.openSession(sessionFactory, EmptyInterceptor.INSTANCE); session.setFlushMode(FlushMode.AUTO);