Hibernate does not return any result

Thread Solved

Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training

Hibernate does not return any result

 
0
  #1
Nov 20th, 2009
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.
  1. <?xml version='1.0' encoding='utf-8'?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4.  
  5. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  6.  
  7. <hibernate-configuration>
  8.  
  9. <session-factory>
  10. <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
  11. <property name="hibernate.connection.url">jdbc:jtds:sqlserver://localhost:1433;databseName=SQLTutorial;integratedSecurity=true;</property>
  12. <!--property name="hibernate.connection.username"></property>
  13. <property name="hibernate.connection.password"></property-->
  14. <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
  15. <property name="show_sql">true</property>
  16. <property name="transaction.factory_class">
  17. org.hibernate.transaction.JDBCTransactionFactory
  18. </property>
  19. <property name="hibernate.cache.provider_class">
  20. org.hibernate.cache.HashtableCacheProvider
  21. </property>
  22. <property name="current_session_context_class">thread</property>
  23. <property name="hibernate.hbm2ddl.auto">update</property>
  24.  
  25. <mapping resource="hibernate\tutorials\Department.hbm.xml"/>
  26.  
  27. </session-factory>
  28.  
  29. </hibernate-configuration>
Am I missing something here?
And my hbm mappings are
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  5.  
  6. <hibernate-mapping package="hibernate.tutorials">
  7. <class name="Department" table="Department">
  8. <id name="id" column="DEPT_ID" type="long">
  9. <generator class="native"/>
  10. </id>
  11. <property name="departmentName" column="DEPT_NAME"/>
  12. </class>
  13. <class name="Employee" table="EMPLOYEE">
  14. <id name="id" column="EMP_ID">
  15. <generator class="native"/>
  16. </id>
  17. <property name="firstName" column="FIRST_NAME"/>
  18. <property name="lastName" column="LAST_NAME"/>
  19. <!--one-to-one name="department" class="Department"/-->
  20. </class>
  21. </hibernate-mapping>

The output that I always get is
  1. Hibernate: select this_.EMP_ID as EMP1_1_0_, this_.FIRST_NAME as FIRST2_1_0_, this_.LAST_NAME as LAST3_1_0_ from EMPLOYEE this_
Also, I have successfully retrieved the result sets using plain JDBC
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training

Seems a Communication Gap

 
0
  #2
Nov 24th, 2009
Seems there's a communication gap between Hibernate and SQL Server Express Edition (2005/2008).

I tried to use Hibernate with SQL Server 2005 and 2008 Express Edition but in vain.

Finally, gave up and used MySQL. It gives me the expected result.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training
 
0
  #3
Nov 24th, 2009
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
  1.  
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <!DOCTYPE hibernate-mapping PUBLIC
  5. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  6. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  7.  
  8. <hibernate-mapping package="hibernate.tutorials">
  9. <class name="Department" table="Department" schema="dbo" catalog="SQLTutorial">
  10. <id name="id" column="DEPT_ID" type="long">
  11. <generator class="native"/>
  12. </id>
  13. <property name="departmentName" column="DEPT_NAME"/>
  14. </class>
  15. <class name="Employee" table="EMPLOYEE" schema="dbo" catalog="SQLTutorial">
  16. <id name="id" column="EMP_ID">
  17. <generator class="native"/>
  18. </id>
  19. <property name="firstName" column="FIRST_NAME"/>
  20. <property name="lastName" column="LAST_NAME"/>
  21. <many-to-one name="department">
  22. <column name="DEPT_ID" />
  23. </many-to-one>
  24. </class>
  25. </hibernate-mapping>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 524 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC