This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate does not return any result

 
umar ali karimi
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there no error? Are you using printStackTrace in the exceptions?
 
umar ali karimi
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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: 423
  • 0
  • Mark post as helpful
  • send pies
  • 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>
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic