@Test public void testFindForUser() throws Exception { // first create and save a user final User user1 = new User("xXx", "vin", "disel", "*****@*****.**"); final User user2 = new User("spiderman", "peter", "parker", "*****@*****.**"); final User user3 = new User("ironman", "tony", "stark", "*****@*****.**"); transactionHelper.executeInTransaction( new VoidRunnable() { @Override public void doRun(final EntityManager entityManager) throws Exception { transactionHelper.persist(user1); transactionHelper.persist(user2); transactionHelper.persist(user3); } }); // we expect the database to be empty Assert.assertEquals(0, taskDao.loadAll().size()); // write access must be executed within a transaction transactionHelper.executeInTransaction( new VoidRunnable() { @Override public void doRun(final EntityManager entityManager) throws Exception { final Task task1 = new Task("aaa", Category.IDEA, true, user1); final Task task2 = new Task("bbb", Category.TODO, false, user1); final Task task3 = new Task("ccc", Category.IDEA, false, user2); taskDao.persist(task1); taskDao.persist(task2); taskDao.persist(task3); } }); Assert.assertEquals(3, taskDao.loadAll().size()); Assert.assertEquals(2, taskDao.findForUser(user1).size()); Assert.assertEquals(1, taskDao.findForUser(user2).size()); Assert.assertEquals(0, taskDao.findForUser(user3).size()); }