Tabnine Logo
HibernateTemplate
Code IndexAdd Tabnine to your IDE (free)

How to use
HibernateTemplate
in
org.springframework.orm.hibernate5

Best Java code snippets using org.springframework.orm.hibernate5.HibernateTemplate (Showing top 20 results out of 315)

Refine searchRefine arrow

  • Session
  • Nullable
origin: spring-projects/spring-framework

@Override
public void delete(Object entity) throws DataAccessException {
  delete(entity, null);
}
origin: spring-projects/spring-framework

/**
 * Create a HibernateTemplate for the given SessionFactory.
 * Only invoked if populating the DAO with a SessionFactory reference!
 * <p>Can be overridden in subclasses to provide a HibernateTemplate instance
 * with different configuration, or a custom HibernateTemplate subclass.
 * @param sessionFactory the Hibernate SessionFactory to create a HibernateTemplate for
 * @return the new HibernateTemplate instance
 * @see #setSessionFactory
 */
protected HibernateTemplate createHibernateTemplate(SessionFactory sessionFactory) {
  return new HibernateTemplate(sessionFactory);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object get(String entityName, Serializable id) throws DataAccessException {
  return get(entityName, id, null);
}
origin: spring-projects/spring-framework

@Override
public void saveOrUpdate(final Object entity) throws DataAccessException {
  executeWithNativeSession(session -> {
    checkWriteOperationAllowed(session);
    session.saveOrUpdate(entity);
    return null;
  });
}
origin: spring-projects/spring-framework

@Override
public void replicate(final String entityName, final Object entity, final ReplicationMode replicationMode)
    throws DataAccessException {
  executeWithNativeSession(session -> {
    checkWriteOperationAllowed(session);
    session.replicate(entityName, entity, replicationMode);
    return null;
  });
}
origin: spring-projects/spring-framework

@Override
public void deleteAll(final Collection<?> entities) throws DataAccessException {
  executeWithNativeSession(session -> {
    checkWriteOperationAllowed(session);
    for (Object entity : entities) {
      session.delete(entity);
    }
    return null;
  });
}
origin: spring-projects/spring-framework

@Override
public void delete(final Object entity, @Nullable final LockMode lockMode) throws DataAccessException {
  executeWithNativeSession(session -> {
    checkWriteOperationAllowed(session);
    if (lockMode != null) {
      session.buildLockRequest(new LockOptions(lockMode)).lock(entity);
    }
    session.delete(entity);
    return null;
  });
}
origin: spring-projects/spring-framework

@Override
@Nullable
public <T> T get(final Class<T> entityClass, final Serializable id, @Nullable final LockMode lockMode)
    throws DataAccessException {
  return executeWithNativeSession(session -> {
    if (lockMode != null) {
      return session.get(entityClass, id, new LockOptions(lockMode));
    }
    else {
      return session.get(entityClass, id);
    }
  });
}
origin: spring-projects/spring-framework

@Override
public void update(final Object entity, @Nullable final LockMode lockMode) throws DataAccessException {
  executeWithNativeSession(session -> {
    checkWriteOperationAllowed(session);
    session.update(entity);
    if (lockMode != null) {
      session.buildLockRequest(new LockOptions(lockMode)).lock(entity);
    }
    return null;
  });
}
origin: spring-projects/spring-framework

@Override
public Object load(final String entityName, final Serializable id, @Nullable final LockMode lockMode)
    throws DataAccessException {
  return nonNull(executeWithNativeSession(session -> {
    if (lockMode != null) {
      return session.load(entityName, id, new LockOptions(lockMode));
    }
    else {
      return session.load(entityName, id);
    }
  }));
}
origin: spring-projects/spring-framework

/**
 * Return the Hibernate SessionFactory used by this DAO.
 */
@Nullable
public final SessionFactory getSessionFactory() {
  return (this.hibernateTemplate != null ? this.hibernateTemplate.getSessionFactory() : null);
}
origin: spring-projects/spring-framework

@Override
public void refresh(final Object entity, @Nullable final LockMode lockMode) throws DataAccessException {
  executeWithNativeSession(session -> {
    if (lockMode != null) {
      session.refresh(entity, new LockOptions(lockMode));
    }
    else {
      session.refresh(entity);
    }
    return null;
  });
}
origin: apache/servicemix-bundles

@Override
public void update(final String entityName, final Object entity, @Nullable final LockMode lockMode)
    throws DataAccessException {
  executeWithNativeSession(session -> {
    checkWriteOperationAllowed(session);
    session.update(entityName, entity);
    if (lockMode != null) {
      session.buildLockRequest(new LockOptions(lockMode)).lock(entityName, entity);
    }
    return null;
  });
}
origin: micromata/projectforge

/**
 * 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.");
}
origin: apache/servicemix-bundles

@Override
public <T> T load(final Class<T> entityClass, final Serializable id, @Nullable final LockMode lockMode)
    throws DataAccessException {
  return nonNull(executeWithNativeSession(session -> {
    if (lockMode != null) {
      return session.load(entityClass, id, new LockOptions(lockMode));
    }
    else {
      return session.load(entityClass, id);
    }
  }));
}
origin: spring-projects/spring-framework

@Override
public void evict(final Object entity) throws DataAccessException {
  executeWithNativeSession(session -> {
    session.evict(entity);
    return null;
  });
}
origin: spring-projects/spring-framework

@Override
public boolean contains(final Object entity) throws DataAccessException {
  Boolean result = executeWithNativeSession(session -> session.contains(entity));
  Assert.state(result != null, "No contains result");
  return result;
}
origin: spring-projects/spring-framework

@Override
public void lock(final String entityName, final Object entity, final LockMode lockMode)
    throws DataAccessException {
  executeWithNativeSession(session -> {
    session.buildLockRequest(new LockOptions(lockMode)).lock(entityName, entity);
    return null;
  });
}
origin: spring-projects/spring-webflow

public void templateSave(Object entity) {
  template.save(entity);
}
origin: micromata/projectforge

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public List<O> internalLoadAll()
{
 return (List<O>) hibernateTemplate.find("from " + clazz.getSimpleName() + " t");
}
org.springframework.orm.hibernate5HibernateTemplate

Javadoc

Helper class that simplifies Hibernate data access code. Automatically converts HibernateExceptions into DataAccessExceptions, following the org.springframework.dao exception hierarchy.

The central method is execute, supporting Hibernate access code implementing the HibernateCallback interface. It provides Hibernate Session handling such that neither the HibernateCallback implementation nor the calling code needs to explicitly care about retrieving/closing Hibernate Sessions, or handling Session lifecycle exceptions. For typical single step actions, there are various convenience methods (find, load, saveOrUpdate, delete).

Can be used within a service implementation via direct instantiation with a SessionFactory reference, or get prepared in an application context and given to services as bean reference. Note: The SessionFactory should always be configured as bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

NOTE: Hibernate access code can also be coded against the native Hibernate Session. Hence, for newly started projects, consider adopting the standard Hibernate style of coding against SessionFactory#getCurrentSession(). Alternatively, use #execute(HibernateCallback) with Java 8 lambda code blocks against the callback-provided Session which results in elegant code as well, decoupled from the Hibernate Session lifecycle. The remaining operations on this HibernateTemplate are deprecated in the meantime and primarily exist as a migration helper for older Hibernate 3.x/4.x data access code in existing applications.

Most used methods

  • delete
  • save
  • <init>
    Create a new HibernateTemplate instance.
  • find
  • get
  • load
  • update
  • getSessionFactory
    Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
  • executeWithNativeSession
    Execute the action specified by the given action object within a native Session. This execute varian
  • findByNamedParam
  • merge
  • afterPropertiesSet
  • merge,
  • afterPropertiesSet,
  • createSessionProxy,
  • disableFilters,
  • doExecute,
  • enableFilters,
  • findByCriteria,
  • findByNamedQueryAndNamedParam,
  • getFilterNames,
  • isCheckWriteOperations

Popular in Java

  • Reactive rest calls using spring rest template
  • getExternalFilesDir (Context)
  • findViewById (Activity)
  • setScale (BigDecimal)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • JPanel (javax.swing)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now