use of org.hibernate.Criteria in project java-design-patterns by iluwatar.
the class WizardDaoImpl method findByName.
@Override
public Wizard findByName(String name) {
Session session = getSession();
Transaction tx = null;
Wizard result = null;
try {
tx = session.beginTransaction();
Criteria criteria = session.createCriteria(persistentClass);
criteria.add(Restrictions.eq("name", name));
result = (Wizard) criteria.uniqueResult();
for (Spellbook s : result.getSpellbooks()) {
s.getSpells().size();
}
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
return result;
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class NaturalIdInvalidationTest method getCitizenWithCriteria.
private void getCitizenWithCriteria(SessionFactory sf) throws Exception {
withTxSession(sf, s -> {
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();
});
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class NaturalIdInvalidationTest method getState.
private State getState(Session s, String name) {
Criteria criteria = s.createCriteria(State.class);
criteria.add(Restrictions.eq("name", name));
criteria.setCacheable(true);
return (State) criteria.list().get(0);
}
use of org.hibernate.Criteria in project hibernate-orm by hibernate.
the class NaturalIdInvalidationTest method deleteCitizenWithCriteria.
private void deleteCitizenWithCriteria(SessionFactory sf) throws Exception {
withTxSession(sf, s -> {
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);
Citizen c = (Citizen) criteria.uniqueResult();
s.delete(c);
});
}
use of org.hibernate.Criteria in project head by mifos.
the class LegacyLoanDao method getTotalOutstandingPrincipalOfLoanAccountsInActiveGoodStanding.
@SuppressWarnings("unchecked")
public BigDecimal getTotalOutstandingPrincipalOfLoanAccountsInActiveGoodStanding(final Short branchId, final Short loanOfficerId, final Short loanProductId) throws PersistenceException {
BigDecimal loanBalanceAmount = new BigDecimal(0);
try {
Session session = StaticHibernateUtil.getSessionTL();
Criteria criteria = session.createCriteria(LoanBO.class).setProjection(Projections.sum("loanBalance.amount")).add(Restrictions.eq("accountState.id", (short) 5)).add(Restrictions.eq("office.officeId", branchId));
if (loanOfficerId != (short) -1) {
criteria.add(Restrictions.eq("personnel.personnelId", loanOfficerId));
}
if (loanProductId != (short) -1) {
criteria.add(Restrictions.eq("loanOffering.prdOfferingId", loanProductId));
}
List list = criteria.list();
loanBalanceAmount = (BigDecimal) list.get(0);
} catch (Exception e) {
throw new PersistenceException(e);
}
return loanBalanceAmount;
}
Aggregations