Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:42:41+00:00 2026-05-29T04:42:41+00:00

I have the following 2 methods I’m testing from a DAO: public List<T> findAll()

  • 0

I have the following 2 methods I’m testing from a DAO:

public List<T> findAll() {
    if (logger.isDebugEnabled()) {
        logger.debug("findAll");
    }
    return currentSession().createCriteria(getPersistentClass()).list();
}

public int count() {
    if (logger.isDebugEnabled()) {
        logger.debug("count");
    }
    return ((Number) currentSession().createCriteria(getPersistentClass()).
            setProjection(Projections.rowCount()).
            uniqueResult()).intValue();
}

Test snippet:

@Test
@Transactional(isolation = Isolation.SERIALIZABLE)
public void testFindAll(){
    Assert.assertEquals(2566, this.employeeHibernateDAO.findAll().size());
}

@Test
@Transactional(isolation = Isolation.SERIALIZABLE)
public void testCount(){
    Assert.assertEquals(2566, this.employeeHibernateDAO.count());
}

There are a total of 2566 entries on the table, and count returns successfully with its count however findAll does not.

Error:

java.lang.AssertionError: 
Expected :2566
Actual   :0
    at org.junit.Assert.fail(Assert.java:91)
    at org.junit.Assert.failNotEquals(Assert.java:645)
    at org.junit.Assert.assertEquals(Assert.java:126)
    at org.junit.Assert.assertEquals(Assert.java:470)
    at org.junit.Assert.assertEquals(Assert.java:454)
    at com.develop.test.data.dao.EmployeeDAOTest.testFindAll(EmployeeDAOTest.java:53)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

So given that error, it is actually returning 0 on that specific method. I cannot figure out why considering count is successful. Any help?

Edit:
SQL for count():

09:56:15.180 [main] DEBUG org.hibernate.SQL - 
    select
        count(*) as y0_ 
    from
        EMPLOYEE this_
Hibernate: 
    select
        count(*) as y0_ 
    from
        EMPLOYEE this_

SQL for findAll() (employee3 refers to an Updated-By field):

09:56:15.243 [main] DEBUG org.hibernate.SQL - 
    select
        this_.EMP_ID as EMP1_5_2_,
        this_.ISACTIVE as ISACTIVE5_2_,
        this_.COMPANY_CODE as COMPANY12_5_2_,
        this_.CORP_TITLE as CORP3_5_2_,
        this_.DEPT_CODE as DEPT13_5_2_,
        this_.E_MAIL as E4_5_2_,
        this_.EMP_FIRST_NAME as EMP5_5_2_,
        this_.HIRE_DATE as HIRE6_5_2_,
        this_.JOB_CODE as JOB7_5_2_,
        this_.JOB_TITLE_DESC as JOB8_5_2_,
        this_.EMP_LAST_NAME as EMP9_5_2_,
        this_.MANAGER_ID as MANAGER14_5_2_,
        this_.MANAGER_INDC as MANAGER10_5_2_,
        this_.EMP_MIDDLE_NAME as EMP11_5_2_,
        preference2_.EMP_ID as EMP1_13_0_,
        preference2_.UPDATED_BY as UPDATED4_13_0_,
        preference2_.UPDATED_DATE as UPDATED2_13_0_,
        preference2_.LANGUAGE as LANGUAGE13_0_,
        employee3_.EMP_ID as EMP1_5_1_,
        employee3_.ISACTIVE as ISACTIVE5_1_,
        employee3_.COMPANY_CODE as COMPANY12_5_1_,
        employee3_.CORP_TITLE as CORP3_5_1_,
        employee3_.DEPT_CODE as DEPT13_5_1_,
        employee3_.E_MAIL as E4_5_1_,
        employee3_.EMP_FIRST_NAME as EMP5_5_1_,
        employee3_.HIRE_DATE as HIRE6_5_1_,
        employee3_.JOB_CODE as JOB7_5_1_,
        employee3_.JOB_TITLE_DESC as JOB8_5_1_,
        employee3_.EMP_LAST_NAME as EMP9_5_1_,
        employee3_.MANAGER_ID as MANAGER14_5_1_,
        employee3_.MANAGER_INDC as MANAGER10_5_1_,
        employee3_.EMP_MIDDLE_NAME as EMP11_5_1_ 
    from
        EMPLOYEE this_ 
    inner join
        PREFERENCE preference2_ 
            on this_.EMP_ID=preference2_.EMP_ID 
    left outer join
        EMPLOYEE employee3_ 
            on preference2_.UPDATED_BY=employee3_.EMP_ID
Hibernate: 
    select
        this_.EMP_ID as EMP1_5_2_,
        this_.ISACTIVE as ISACTIVE5_2_,
        this_.COMPANY_CODE as COMPANY12_5_2_,
        this_.CORP_TITLE as CORP3_5_2_,
        this_.DEPT_CODE as DEPT13_5_2_,
        this_.E_MAIL as E4_5_2_,
        this_.EMP_FIRST_NAME as EMP5_5_2_,
        this_.HIRE_DATE as HIRE6_5_2_,
        this_.JOB_CODE as JOB7_5_2_,
        this_.JOB_TITLE_DESC as JOB8_5_2_,
        this_.EMP_LAST_NAME as EMP9_5_2_,
        this_.MANAGER_ID as MANAGER14_5_2_,
        this_.MANAGER_INDC as MANAGER10_5_2_,
        this_.EMP_MIDDLE_NAME as EMP11_5_2_,
        preference2_.EMP_ID as EMP1_13_0_,
        preference2_.UPDATED_BY as UPDATED4_13_0_,
        preference2_.UPDATED_DATE as UPDATED2_13_0_,
        preference2_.LANGUAGE as LANGUAGE13_0_,
        employee3_.EMP_ID as EMP1_5_1_,
        employee3_.ISACTIVE as ISACTIVE5_1_,
        employee3_.COMPANY_CODE as COMPANY12_5_1_,
        employee3_.CORP_TITLE as CORP3_5_1_,
        employee3_.DEPT_CODE as DEPT13_5_1_,
        employee3_.E_MAIL as E4_5_1_,
        employee3_.EMP_FIRST_NAME as EMP5_5_1_,
        employee3_.HIRE_DATE as HIRE6_5_1_,
        employee3_.JOB_CODE as JOB7_5_1_,
        employee3_.JOB_TITLE_DESC as JOB8_5_1_,
        employee3_.EMP_LAST_NAME as EMP9_5_1_,
        employee3_.MANAGER_ID as MANAGER14_5_1_,
        employee3_.MANAGER_INDC as MANAGER10_5_1_,
        employee3_.EMP_MIDDLE_NAME as EMP11_5_1_ 
    from
        EMPLOYEE this_ 
    inner join
        PREFERENCE preference2_ 
            on this_.EMP_ID=preference2_.EMP_ID 
    left outer join
        EMPLOYEE employee3_ 
            on preference2_.UPDATED_BY=employee3_.EMP_ID
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:42:43+00:00Added an answer on May 29, 2026 at 4:42 am

    Is it not conceivable that you actually have zero rows for the joined query? Does the join to PREFERENCE succeed?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following C# methods: public Vector2 GetVectorToTile(int x, int y) { return
I have the following UserController methods: public ActionResult DeleteThread(int RootMessageID) { _repository.DeleteMessageThread(RootMessageID); return RedirectToAction(ActionMessageSuccess,
I have the following two methods that get data from my DB and return
I have the following methods: public <T> T fromJson( Reader jsonData, Class<T> clazz )
I have the following methods on the server (RIA services): public IQueryable<Customer> GetCustomers() {
I’m after some C# code that will have the following methods that will return
I have the following action methods: public ActionResult ProfileSettings() { Context con = new
Scenario I have the following methods: public void AddItemSecurity(int itemId, int[] userIds) public int[]
Say I have the following methods: public static void MyCoolMethod(params object[] allObjects) { }
My Action class have the following methods, 1.add 2.edit 3.loadEdit 4.remove 5.list 6.execute in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.