Java tutorial
/* * Copyright 2005-2015 shopxx.net. All rights reserved. * Support: http://3936242.01p.com/ * License: http://3936242.01p.com/license */ package net.shopxx.dao.impl; import javax.persistence.NoResultException; import net.shopxx.dao.PaymentDao; import net.shopxx.entity.Payment; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Repository; @Repository("paymentDaoImpl") public class PaymentDaoImpl extends BaseDaoImpl<Payment, Long> implements PaymentDao { public Payment findBySn(String sn) { if (StringUtils.isEmpty(sn)) { return null; } String jpql = "select payment from Payment payment where lower(payment.sn) = lower(:sn)"; try { return entityManager.createQuery(jpql, Payment.class).setParameter("sn", sn).getSingleResult(); } catch (NoResultException e) { return null; } } }