| | |
Hibernate does not return any result
Thread Solved |
•
•
Join Date: Aug 2007
Posts: 81
Reputation:
Solved Threads: 10
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
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)
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:jtds:sqlserver://localhost:1433;databseName=SQLTutorial;integratedSecurity=true;</property> <!--property name="hibernate.connection.username"></property> <property name="hibernate.connection.password"></property--> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="show_sql">true</property> <property name="transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory </property> <property name="hibernate.cache.provider_class"> org.hibernate.cache.HashtableCacheProvider </property> <property name="current_session_context_class">thread</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="hibernate\tutorials\Department.hbm.xml"/> </session-factory> </hibernate-configuration>
And my hbm mappings are
Java Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="hibernate.tutorials"> <class name="Department" table="Department"> <id name="id" column="DEPT_ID" type="long"> <generator class="native"/> </id> <property name="departmentName" column="DEPT_NAME"/> </class> <class name="Employee" table="EMPLOYEE"> <id name="id" column="EMP_ID"> <generator class="native"/> </id> <property name="firstName" column="FIRST_NAME"/> <property name="lastName" column="LAST_NAME"/> <!--one-to-one name="department" class="Department"/--> </class> </hibernate-mapping>
The output that I always get is
Java Syntax (Toggle Plain Text)
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_
•
•
Join Date: Aug 2007
Posts: 81
Reputation:
Solved Threads: 10
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
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)
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="hibernate.tutorials"> <class name="Department" table="Department" schema="dbo" catalog="SQLTutorial"> <id name="id" column="DEPT_ID" type="long"> <generator class="native"/> </id> <property name="departmentName" column="DEPT_NAME"/> </class> <class name="Employee" table="EMPLOYEE" schema="dbo" catalog="SQLTutorial"> <id name="id" column="EMP_ID"> <generator class="native"/> </id> <property name="firstName" column="FIRST_NAME"/> <property name="lastName" column="LAST_NAME"/> <many-to-one name="department"> <column name="DEPT_ID" /> </many-to-one> </class> </hibernate-mapping>
![]() |
Similar Threads
- return a result from asp.net web service (ASP.NET)
- ERROR: supplied argument is not a valid MySQL result resource (PHP)
- return result set in SPs (MySQL)
- Compiler says: "missing return statement"...even though I have a return statement! (Java)
- help me - An Hibernate error (Java)
- Return wont work in a function - why? (Python)
- Return number of rows in table (MySQL)
- Always return the same date(s) (PHP)
- solution for not all code paths return a value for bool (C#)
- How to return more than one value from a method? (C#)
Other Threads in the Java Forum
- Previous Thread: DataTree issue
- Next Thread: MIDlet - using socket and databases
Views: 524 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
access actionlistener android api apple applet application arguments array arrays automation binary bluetooth c++ chat class classes client code combobox compiler component converter coordinates database db design desktop detection eclipse error event exception fast file fractal game givemetehcodez graphics gridlayout gui helpwithhomework html image input interface j2me java javaprojects jmf jni jpanel jtable julia list loop map method methods mobile netbeans newbie number object objects os pattern phone pixel problem program programming project read recursion regex remote remove robot scanner screen search server set size sms socket sort sql string swing test text threads time timer transfer tree update windows





