943,162 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 1318
  • Java RSS
Nov 20th, 2009
0

Hibernate does not return any result

Expand Post »
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.
Java Syntax (Toggle Plain Text)
  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
Java Syntax (Toggle Plain Text)
  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
Java Syntax (Toggle Plain Text)
  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
Reputation Points: 16
Solved Threads: 11
Junior Poster in Training
lookof2day is offline Offline
83 posts
since Aug 2007
Nov 24th, 2009
0

Seems a Communication Gap

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.
Reputation Points: 16
Solved Threads: 11
Junior Poster in Training
lookof2day is offline Offline
83 posts
since Aug 2007
Nov 24th, 2009
0
Re: Hibernate does not return any result
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
Java Syntax (Toggle Plain Text)
  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>
Reputation Points: 16
Solved Threads: 11
Junior Poster in Training
lookof2day is offline Offline
83 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: DataTree issue
Next Thread in Java Forum Timeline: Writing to DB9 port





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC