Codota Logo
HibernateTemplate.load
Code IndexAdd Codota to your IDE (free)

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

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

  • Common ways to obtain HibernateTemplate
private void myMethod () {
HibernateTemplate h =
  • Codota IconSessionFactory sessionFactory;new HibernateTemplate(sessionFactory)
  • Smart code suggestions by Codota
}
origin: spring-projects/spring-framework

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

@Override
public <T> T load(Class<T> entityClass, Serializable id) throws DataAccessException {
  return load(entityClass, id, null);
}
origin: org.springframework/spring-orm

@Override
public Object load(String entityName, Serializable id) throws DataAccessException {
  return load(entityName, id, null);
}
origin: org.springframework/spring-orm

@Override
public <T> T load(Class<T> entityClass, Serializable id) throws DataAccessException {
  return load(entityClass, id, null);
}
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: micromata/projectforge

/**
 * Object will be marked as deleted (boolean flag), therefore undelete is always possible without any loss of data.
 *
 * @param obj
 */
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void markAsDeleted(final O obj) throws AccessException
{
 Validate.notNull(obj);
 if (obj.getId() == null) {
  final String msg = "Could not delete object unless id is not given:" + obj.toString();
  log.error(msg);
  throw new RuntimeException(msg);
 }
 final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
 checkPartOfCurrentTenant(obj, OperationType.DELETE);
 checkLoggedInUserDeleteAccess(obj, dbObj);
 accessChecker.checkRestrictedOrDemoUser();
 internalMarkAsDeleted(obj);
}
origin: spring-projects/spring-ldap

@Test
public void testUpdate() {
  String dn = "cn=Some Person,ou=company1,ou=Sweden";
  OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  person.setLastname("Updated Person");
  person.setDescription("Updated description");
  dummyDao.update(person);
  log.debug("Verifying result");
  Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
    public Object mapFromAttributes(Attributes attributes) throws NamingException {
      assertThat(attributes.get("sn").get()).isEqualTo("Updated Person");
      assertThat(attributes.get("description").get()).isEqualTo("Updated description");
      return new Object();
    }
  });
  OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  assertThat(updatedPerson.getLastname()).isEqualTo("Updated Person");
  assertThat(updatedPerson.getDescription()).isEqualTo("Updated description");
  assertThat(ldapResult).isNotNull();
}
origin: spring-projects/spring-ldap

@Test
public void testUnbindWithException() {
  String dn = "cn=Some Person,ou=company1,ou=Sweden";
  OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  try {
    // Perform test
    dummyDao.unbindWithException(person);
    fail("DummyException expected");
  }
  catch (DummyException expected) {
    assertThat(true).isTrue();
  }
  person = null;
  // Verify result - check that the operation was properly rolled back
  Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
    public Object mapFromAttributes(Attributes attributes) throws NamingException {
      // Just verify that the entry still exists.
      return new Object();
    }
  });
  person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); // will
  // throw
  // exception
  // of
  // person
  // does
  // not
  // exist
  assertThat(ldapResult).isNotNull();
}
origin: spring-projects/spring-ldap

@Test
public void testUnbindWithException() {
  String dn = "cn=Some Person,ou=company1,ou=Sweden";
  OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  try {
    // Perform test
    dummyDao.unbindWithException(person);
    fail("DummyException expected");
  }
  catch (DummyException expected) {
    assertThat(true).isTrue();
  }
  person = null;
  // Verify result - check that the operation was properly rolled back
  Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
    public Object mapFromAttributes(Attributes attributes) throws NamingException {
      // Just verify that the entry still exists.
      return new Object();
    }
  });
  person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1)); // will
  // throw
  // exception
  // of
  // person
  // does
  // not
  // exist
  assertThat(ldapResult).isNotNull();
}
origin: spring-projects/spring-ldap

@Test
public void testUpdate() {
  String dn = "cn=Some Person,ou=company1,ou=Sweden";
  OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  person.setLastname("Updated Person");
  person.setDescription("Updated description");
  dummyDao.update(person);
  log.debug("Verifying result");
  Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
    public Object mapFromAttributes(Attributes attributes) throws NamingException {
      assertThat(attributes.get("sn").get()).isEqualTo("Updated Person");
      assertThat(attributes.get("description").get()).isEqualTo("Updated description");
      return new Object();
    }
  });
  OrgPerson updatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  assertThat(updatedPerson.getLastname()).isEqualTo("Updated Person");
  assertThat(updatedPerson.getDescription()).isEqualTo("Updated description");
  assertThat(ldapResult).isNotNull();
}
origin: spring-projects/spring-ldap

@Test
public void testUpdateWithException() {
  String dn = "cn=Some Person,ou=company1,ou=Sweden";
  OrgPerson originalPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  originalPerson.setLastname("fooo");
  try {
    dummyDao.updateWithException(originalPerson);
    fail("DummyException expected");
  }
  catch (DummyException expected) {
    assertThat(true).isTrue();
  }
  log.debug("Verifying result");
  Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
    public Object mapFromAttributes(Attributes attributes) throws NamingException {
      assertThat(attributes.get("sn").get()).as("Person").isNotNull();
      assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
      return new Object();
    }
  });
  OrgPerson notUpdatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  assertThat(notUpdatedPerson.getLastname()).isEqualTo("Person");
  assertThat(notUpdatedPerson.getDescription()).isEqualTo("Sweden, Company1, Some Person");
  assertThat(ldapResult).isNotNull();
  // no need to assert if notUpdatedPerson exists
}
origin: spring-projects/spring-ldap

@Test
public void testUpdateWithException() {
  String dn = "cn=Some Person,ou=company1,ou=Sweden";
  OrgPerson originalPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  originalPerson.setLastname("fooo");
  try {
    dummyDao.updateWithException(originalPerson);
    fail("DummyException expected");
  }
  catch (DummyException expected) {
    assertThat(true).isTrue();
  }
  log.debug("Verifying result");
  Object ldapResult = ldapTemplate.lookup(dn, new AttributesMapper() {
    public Object mapFromAttributes(Attributes attributes) throws NamingException {
      assertThat(attributes.get("sn").get()).as("Person").isNotNull();
      assertThat(attributes.get("description").get()).isEqualTo("Sweden, Company1, Some Person");
      return new Object();
    }
  });
  OrgPerson notUpdatedPerson = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
  assertThat(notUpdatedPerson.getLastname()).isEqualTo("Person");
  assertThat(notUpdatedPerson.getDescription()).isEqualTo("Sweden, Company1, Some Person");
  assertThat(ldapResult).isNotNull();
  // no need to assert if notUpdatedPerson exists
}
origin: spring-projects/spring-ldap

  @Test
  public void testUnbind() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    // Perform test
    OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
    dummyDao.unbind(person);

    try {
      // Verify result - check that the operation was not rolled back
      ldapTemplate.lookup(dn);
      fail("NameNotFoundException expected");
    }
    catch (NameNotFoundException expected) {
      assertThat(true).isTrue();
    }

    person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1));
    assertThat(person).isNull();
  }
}
origin: micromata/projectforge

/**
 * User can modify own setting, this method ensures that only such properties will be updated, the user's are allowed
 * to.
 * 
 * @param user
 */
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void updateMyAccount(final PFUserDO user)
{
 accessChecker.checkRestrictedOrDemoUser();
 final PFUserDO contextUser = ThreadLocalUserContext.getUser();
 Validate.isTrue(user.getId().equals(contextUser.getId()) == true);
 final PFUserDO dbUser = getHibernateTemplate().load(clazz, user.getId(), LockMode.PESSIMISTIC_WRITE);
 final String[] ignoreFields = { "deleted", "password", "lastLogin", "loginFailures", "username", "stayLoggedInKey",
   "authenticationToken", "rights" };
 final ModificationStatus result = HistoryBaseDaoAdapter.wrappHistoryUpdate(dbUser,
   () -> copyValues(user, dbUser, ignoreFields));
 if (result != ModificationStatus.NONE) {
  dbUser.setLastUpdate();
  log.info("Object updated: " + dbUser.toString());
  copyValues(user, contextUser, ignoreFields);
 } else {
  log.info("No modifications detected (no update needed): " + dbUser.toString());
 }
 getUserGroupCache().updateUser(user);
}
origin: spring-projects/spring-ldap

  @Test
  public void testUnbind() {
    String dn = "cn=Some Person,ou=company1,ou=Sweden";
    // Perform test
    OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
    dummyDao.unbind(person);

    try {
      // Verify result - check that the operation was not rolled back
      ldapTemplate.lookup(dn);
      fail("NameNotFoundException expected");
    }
    catch (NameNotFoundException expected) {
      assertThat(true).isTrue();
    }

    person = (OrgPerson) this.hibernateTemplate.get(OrgPerson.class, new Integer(1));
    assertThat(person).isNull();
  }
}
origin: micromata/projectforge

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void internalMarkAsDeleted(final O obj)
{
 if (HistoryBaseDaoAdapter.isHistorizable(obj) == false) {
  log.error(
    "Object is not historizable. Therefore marking as deleted is not supported. Please use delete instead.");
  throw new InternalErrorException();
 }
 onDelete(obj);
 final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
 onSaveOrModify(obj);
 HistoryBaseDaoAdapter.wrappHistoryUpdate(dbObj, () -> {
  BaseDaoJpaAdapter.beforeUpdateCopyMarkDelete(dbObj, obj);
  copyValues(obj, dbObj, "deleted"); // If user has made additional changes.
  dbObj.setDeleted(true);
  dbObj.setLastUpdate();
  flushSession();
  flushSearchSession();
  return null;
 });
 afterSaveOrModify(obj);
 afterDelete(obj);
 flushSession();
 log.info("Object marked as deleted: " + dbObj.toString());
}
origin: micromata/projectforge

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ)
public void internalUndelete(final O obj)
{
 final O dbObj = hibernateTemplate.load(clazz, obj.getId(), LockMode.PESSIMISTIC_WRITE);
 onSaveOrModify(obj);
 HistoryBaseDaoAdapter.wrappHistoryUpdate(dbObj, () -> {
  BaseDaoJpaAdapter.beforeUpdateCopyMarkUnDelete(dbObj, obj);
  copyValues(obj, dbObj, "deleted"); // If user has made additional changes.
  dbObj.setDeleted(false);
  obj.setDeleted(false);
  dbObj.setLastUpdate();
  obj.setLastUpdate(dbObj.getLastUpdate());
  flushSession();
  flushSearchSession();
  return null;
 });
 afterSaveOrModify(obj);
 afterUndelete(obj);
 log.info("Object undeleted: " + dbObj.toString());
}
origin: spring-projects/spring-ldap

String dn = "cn=Some Person2,ou=company1,ou=Sweden";
String newDn = "cn=Some Person2,ou=company2,ou=Sweden";
OrgPerson person = (OrgPerson) this.hibernateTemplate.load(OrgPerson.class, new Integer(1));
person.setLastname("Updated Person");
person.setDescription("Updated description");
origin: micromata/projectforge

/**
 * @param obj
 * @return true, if already existing entry was updated, otherwise false (e. g. if no entry exists for update).
 */
private boolean internalUpdate(final PersonalContactDO obj)
{
 PersonalContactDO dbObj = null;
 if (obj.getId() != null) {
  dbObj = hibernateTemplate.load(PersonalContactDO.class, obj.getId(), LockMode.PESSIMISTIC_WRITE);
 }
 if (dbObj == null) {
  dbObj = getByContactId(obj.getContactId());
 }
 if (dbObj == null) {
  return false;
 }
 checkAccess(dbObj);
 Validate.isTrue(ObjectUtils.equals(dbObj.getContactId(), obj.getContactId()));
 obj.setId(dbObj.getId());
 // Copy all values of modified user to database object.
 final ModificationStatus modified = dbObj.copyValuesFrom(obj, "owner", "address", "id");
 if (modified == ModificationStatus.MAJOR) {
  dbObj.setLastUpdate();
  log.info("Object updated: " + dbObj.toString());
 }
 return true;
}
origin: micromata/projectforge

/**
 * @param obj
 * @return true, if already existing entry was updated, otherwise false (e. g. if no entry exists for update).
 */
private boolean internalUpdate(final PersonalAddressDO obj)
{
 PersonalAddressDO dbObj = null;
 if (obj.getId() != null) {
  dbObj = hibernateTemplate.load(PersonalAddressDO.class, obj.getId(), LockMode.PESSIMISTIC_WRITE);
 }
 if (dbObj == null) {
  dbObj = getByAddressId(obj.getAddressId());
 }
 if (dbObj == null) {
  return false;
 }
 checkAccess(dbObj);
 Validate.isTrue(ObjectUtils.equals(dbObj.getAddressId(), obj.getAddressId()));
 obj.setId(dbObj.getId());
 // Copy all values of modified user to database object.
 final ModificationStatus modified = dbObj.copyValuesFrom(obj, "owner", "address", "id");
 if (modified == ModificationStatus.MAJOR) {
  dbObj.setLastUpdate();
  log.info("Object updated: " + dbObj.toString());
 }
 return true;
}
org.springframework.orm.hibernate5HibernateTemplateload

Popular methods of HibernateTemplate

  • delete
  • save
  • <init>
    Create a new HibernateTemplate instance.
  • find
  • get
  • 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
  • createSessionProxy
    Create a close-suppressing proxy for the given Hibernate Session. The proxy also prepares returned Q
  • afterPropertiesSet,
  • createSessionProxy,
  • disableFilters,
  • doExecute,
  • enableFilters,
  • findByCriteria,
  • findByNamedQueryAndNamedParam,
  • getFilterNames,
  • isCheckWriteOperations

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • Menu (java.awt)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Stack (java.util)
    The Stack class represents a last-in-first-out (LIFO) stack of objects. It extends class Vector with
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now