use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.
the class OptionElementDAOImpl method findOptionElementFromUser.
@Override
public Collection<OptionElement> findOptionElementFromUser(User user) {
Query query = entityManager.createQuery("SELECT u.optionElementSet FROM " + getUserEntityClass().getName() + " u" + " WHERE u=:user");
query.setParameter("user", user);
try {
return (Collection<OptionElement>) query.getResultList();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of javax.persistence.NonUniqueResultException in project Asqatasun by Asqatasun.
the class OptionElementDAOImpl method findOptionElementFromValueAndOption.
/**
*
* @param value
* @param option
* @return
*/
@Override
public OptionElement findOptionElementFromValueAndOption(String value, Option option) {
Query query = entityManager.createQuery("SELECT oe FROM " + getEntityClass().getName() + " oe" + " WHERE oe.value=:value" + " AND oe.option=:option");
query.setParameter("value", value);
query.setParameter("option", option);
try {
return (OptionElement) query.getSingleResult();
} catch (NoResultException | NonUniqueResultException nre) {
return null;
}
}
use of javax.persistence.NonUniqueResultException in project invesdwin-context-persistence by subes.
the class SimpleTestService method getByName.
public SimpleTestEntity getByName(final String name) {
final SimpleTestEntity example = new SimpleTestEntity();
example.setName(name);
final List<SimpleTestEntity> l = dao.findAll(example);
if (l.size() == 0) {
return null;
} else if (l.size() > 1) {
throw new NonUniqueResultException(String.valueOf(l.size()));
} else {
return l.get(0);
}
}
use of javax.persistence.NonUniqueResultException in project invesdwin-context-persistence by subes.
the class SimpleTestService method getByName.
public SimpleTestEntity getByName(final String name) {
final SimpleTestEntity example = new SimpleTestEntity();
example.setName(name);
final List<SimpleTestEntity> l = dao.findAll(example);
if (l.size() == 0) {
return null;
} else if (l.size() > 1) {
throw new NonUniqueResultException(String.valueOf(l.size()));
} else {
return l.get(0);
}
}
use of javax.persistence.NonUniqueResultException in project tests by datanucleus.
the class JPQLQueryTest method testNonUniqueResultExceptionThrown.
public void testNonUniqueResultExceptionThrown() {
try {
EntityManager em = getEM();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
Person p1 = new Person(101, "Fred", "Flintstone", "fred.flintstone@jpox.com");
em.persist(p1);
Person p2 = new Person(102, "Barney", "Rubble", "barney.rubble@jpox.com");
em.persist(p2);
em.createQuery("SELECT Object(T) FROM " + Person.class.getName() + " T where T.firstName <> 'Wilma' ").getSingleResult();
fail("expected NonUniqueResultException");
} catch (NonUniqueResultException ex) {
// expected
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
} finally {
clean(Person.class);
}
}
Aggregations