Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Object Relational Mapping and the fly likes Hibernate does not return any result Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate does not return any result" Watch "Hibernate does not return any result" New topic
Author

Hibernate does not return any result

umar ali karimi
Greenhorn

Joined: May 18, 2005
Posts: 9
[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
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
Is there no error? Are you using printStackTrace in the exceptions?
umar ali karimi
Greenhorn

Joined: May 18, 2005
Posts: 9
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

Joined: Mar 04, 2009
Posts: 417
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>
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
umar ali karimi
Greenhorn

Joined: May 18, 2005
Posts: 9
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

Joined: May 18, 2005
Posts: 9
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

Joined: Apr 14, 2004
Posts: 10336


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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hibernate does not return any result
 
Similar Threads
Joining tables
problem with hibernate mapping
How to configure xxx.hbm.xml
problem in mapping hibernate class
problem with hibernate