• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query returs empty list but getting results in TOAD

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to retrive all record from a table. The generated sql I copied and excuted in TOAD and got two record. But my Qury object have empty list.

Can some one help me what could be the problem ?

Here is the code :

try {
Query q =
getSession().createQuery("from Templatedetail td");
list = q.list();

} catch (HibernateException e) {
e.printStackTrace();
}
return list;

Generated Qury :
select templatede0_.TEMPLATEID as TEMPLATEID, templatede0_.TEMPLATETYPE as TEMPLATE2_, templatede0_.DETAILDESC as DETAILDESC, templatede0_.OWNERCODE as OWNERCODE from TEMPLATEDETAILS templatede0_

This qury retrieving two record when I executed in TOAD. But my list from Query object is empty.

Mapping File:

<class name="com.test.model.Templatedetail" table="TEMPLATEDETAILS">
<meta attribute="class-description" inherit="false">@hibernate.class table="TEMPLATEDETAILS"</meta>

<id name="templateid" type="java.lang.Long" column="TEMPLATEID">
<meta attribute="field-description">
@hibernate.id generator-class="assigned" type="java.lang.Long" column="TEMPLATEID"

</meta>
<generator class="assigned" />
</id>

<property name="templatetype" type="java.lang.Long" column="TEMPLATETYPE" length="11">
<meta attribute="field-description">@hibernate.property column="TEMPLATETYPE" length="11"</meta>
</property>
<property name="detaildesc" type="java.lang.String" column="DETAILDESC" length="255">
<meta attribute="field-description">@hibernate.property column="DETAILDESC" length="255"</meta>
</property>
<property name="ownercode" type="java.lang.Long" column="OWNERCODE" length="11">
<meta attribute="field-description">@hibernate.property column="OWNERCODE" length="11"</meta>
</property>

<!-- Associations -->


</class>


Used Middlegen to generate Mapping files and beans. Table have one primary hey called templateid.

Thanks
Sudhakar
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FYI, I tried inserting and it workd fine.
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved the puzzle. I have manually insterted records in the database and when tried retrieving got empty list, I tried insterting one record through save() method and tried searching , now I got one record back.

After I inserted records manually I ran commit; command also but not sure why hibernate not able to query the records which are manually inserted in db and only able to retrieve which are programatically inserted.

Thanks
Sudhakar
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you have caching on and it runs the query on the cached set which had no records even though the database now did..

Mark
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to find out whether caching is on/off. I used middlegen to create mapping files and pojo's.

Sudhakar
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sudhakar Tadepalli:
How to find out whether caching is on/off. I used middlegen to create mapping files and pojo's.

Sudhakar



Look at your mapping files. If you've added a <cache /> element to your class then you are asking Hibernate to use the second level cache. The first level cache is (of course) always used. It shouldn't be that though. Is the only difference from your first failed attempt and your second successful one that you forced a commit after running your insert statement in Toad? Because, if I remember right, Toad is configured by default not to commit after every statement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic