5 Ekim 2009 Pazartesi

notes on schuchert jpa tutor 2

the tutor is at http://schuchert.wikispaces.com/JPA+Tutorial+2+-+Working+with+Queries+1

lets follow..
  • comment out the exception in the  unsuccessfulSingleResultTooManyEntries  test case of QueriesTest.. thus, it will pass..
 @Test// (expected = NonUniqueResultException.class)
    public void unsuccessfulSingleResultTooManyEntries() {
insertPerson();
        insertPerson();

        // This will fail because we expect a single result
        // but in fact there are 2 results returned.
        em.createQuery("from Person").getSingleResult();
    }

this is because,  getSingleResult() does not get angry when there are more than one records and just picks the first one..



Hiç yorum yok:

Yorum Gönder