• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate does not return any result

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[color=blue]I've been trying to get a list of values from database using hibernate.
I'm using MS SQL Server XE 2005 and using Hibernate 3.2.2 to fetch DB rows. I've tried JDBC drivers provided by Microsoft as well as jTDS but all I get is an empty list.

Here is my hibernate configuration file.



Am I missing something here?

And my hbm mappings are



The output that I always get is

Also, I have successfully retrieved the result sets using plain JDBC
 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there no error? Are you using printStackTrace in the exceptions?
 
umar ali karimi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No there is no error.

But when I use MySQL, I can see expected results.

It seems there's a communication gap between Hibernate and SQL Server Express Edition(2005/2008).

I tried with both of them on Windows 7 x64 bit platform but in vain.
 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

umar ali karimi wrote:No there is no error.

But when I use MySQL, I can see expected results.

It seems there's a communication gap between Hibernate and SQL Server Express Edition(2005/2008).

I tried with both of them on Windows 7 x64 bit platform but in vain.


So probably the error is in the hibernate.cfg.xml or in the driver.

Try this:
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
 
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

umar ali karimi wrote:
But when I use MySQL, I can see expected results.


Do you mean SQL Server?

Does the user you connect with have permission to select from Department?
 
umar ali karimi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hbm mappings for MS SQL server require additional properties which I just figured out with the help of Netbeans.

Thanks to Netbeans




The additional properties are schema and catalog

I modified the mappings as shown below and it gave me the expected results

 
umar ali karimi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But there's still one question which is haunting me.

Why does not hibernate report any exception like "table or view" does not exist if it is not aware of the schema and catalog and simply returns an empty list.

Any thoughts?
 
Paul Sturrock
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


The additional properties are schema and catalog


Hibernate mappings for SQL Server do not require these. These are required because of the user you connect to your database as. If you use Windows Integrated authentication you do not connect to any particular schema so you need to tell SQL Server which one you are using. If you had conencted using SQL Server authentication you would not need these properties.


Why does not hibernate report any exception like "table or view" does not exist if it is not aware of the schema and catalog and simply returns an empty list. [


This is a detail of how SQL Server is implemented, its not Hibernate. Had it been Oracle and you connected with a user who could not see your department table you would get an error.

 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic