List of usage examples for org.hibernate.criterion Restrictions naturalId
public static NaturalIdentifier naturalId()
From source file:com.purebred.core.dao.EntityDao.java
License:Open Source License
/** * Find entity by natural id, or business key. This method only works for entities that have a single property * marked as @NaturalId. The benefit of calling this method is that Hibernate will try to look up the entity * in the secondary cache.//from ww w. j a va 2s. c o m * * @param propertyName name of the property in the entity that is marked @NaturalId * @param propertyValue value to search for * * @return entity */ public T findByNaturalId(String propertyName, Object propertyValue) { Session session = (Session) getEntityManager().getDelegate(); Criteria criteria = session.createCriteria(getEntityType()); criteria.add(Restrictions.naturalId().set(propertyName, propertyValue)); criteria.setCacheable(true); return (T) criteria.uniqueResult(); }
From source file:com.silverpeas.mailinglist.service.model.dao.MessageDaoImpl.java
License:Open Source License
public Message findMessageByMailId(final String messageId, String componentId) { Criteria criteria = getSession().createCriteria(Message.class); criteria.add(Restrictions.naturalId().set("componentId", componentId).set("messageId", messageId)); return (Message) criteria.uniqueResult(); }
From source file:cz.jirutka.commons.hibernate.HibernateGenericDAO.java
License:Open Source License
public <E extends Persistable> E findByNaturalKey(String property, Object value, Class<E> clazz) throws NoResultException { E entity = (E) createCriteria(clazz).add(Restrictions.naturalId().set(property, value)).setCacheable(true) .setCacheRegion(CACHE_REGION_NATURAL_ID).uniqueResult(); if (entity == null) { throw new NoResultException(String.format("No such entity %s with NaturalId %s = %s", clazz.getSimpleName(), property, value)); }//from www . java 2 s.com return entity; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.DateAttributeLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override// w ww .j a v a 2 s . c o m protected Criterion getCriterionForComparator() { Criterion criterion = null; switch (getComparator()) { case GT: criterion = Restrictions.gt("value", getPattern()); break; case EQ: criterion = Restrictions.eq("value", getPattern()); break; case LT: criterion = Restrictions.lt("value", getPattern()); break; case ANY_ASSIGNMENT: criterion = Restrictions.naturalId(); break; default: throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR); } return criterion; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.EnumAttributeLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w ww. j a v a2s .c o m*/ protected Criterion getCriterionForComparator() { Criterion criterion = null; switch (getComparator()) { case LIKE: criterion = new IteraplanLikeExpression("name", (String) getProcessedPattern(), true); break; case EQ: criterion = Restrictions.eq("name", getProcessedPattern()); break; case ANY_ASSIGNMENT: criterion = Restrictions.naturalId(); break; default: throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR); } return criterion; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.NumberAttributeLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/* w w w . ja v a 2 s . c o m*/ protected Criterion getCriterionForComparator() { String value = "value"; Criterion criterion = null; switch (getComparator()) { case GT: criterion = Restrictions.gt(value, getPattern()); break; case GEQ: criterion = Restrictions.ge(value, getPattern()); break; case EQ: criterion = Restrictions.eq(value, getPattern()); break; case LEQ: criterion = Restrictions.le(value, getPattern()); break; case LT: criterion = Restrictions.lt(value, getPattern()); break; case ANY_ASSIGNMENT: criterion = Restrictions.naturalId(); break; default: throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR); } return criterion; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.ResponsibilityAttributeLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/* ww w .j a v a 2s .c om*/ protected Criterion getCriterionForComparator() { Criterion criterion = null; switch (getComparator()) { case LIKE: criterion = createUserCriterion(); break; case ANY_ASSIGNMENT: criterion = Restrictions.naturalId(); break; default: throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR); } return criterion; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.TextAttributeLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/* w ww .j a va 2s .co m*/ protected Criterion getCriterionForComparator() { Criterion criterion = null; switch (getComparator()) { case LIKE: criterion = new IteraplanLikeExpression("value", (String) getProcessedPattern(), true); break; case ANY_ASSIGNMENT: criterion = Restrictions.naturalId(); break; default: throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR); } return criterion; }
From source file:de.u808.simpleinquest.repository.impl.GenericHibernateDAO.java
License:Apache License
@SuppressWarnings("unchecked") public T findById(final ID id) { T entity;/* ww w .ja v a 2s . c om*/ entity = (T) this.getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) { Criteria criteria = session.createCriteria(getPersistentClass()); criteria.add(Restrictions.naturalId().set("id", id)).setCacheable(true).uniqueResult(); return criteria.uniqueResult(); } }); return entity; }
From source file:org.infinispan.test.hibernate.cache.commons.functional.cluster.NaturalIdInvalidationTest.java
License:LGPL
private void getCitizenWithCriteria(SessionFactory sf) throws Exception { withTxSession(sf, s -> {/*from w w w.j a v a 2 s. co m*/ State france = getState(s, "Ile de France"); Criteria criteria = s.createCriteria(Citizen.class); criteria.add(Restrictions.naturalId().set("ssn", "1234").set("state", france)); criteria.setCacheable(true); criteria.list(); }); }