-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: ODBC-error with MS SQL Server and parent/child relation
PostPosted: Tue Feb 24, 2004 9:42 am 
Newbie

Joined: Fri Feb 20, 2004 7:37 am
Posts: 12
Hi,

I have a very bad problem when trying to load or query for persistent objects.
I'm getting an ODBC-error S1002 - invalid descriptor index - but only under specific circumstances!

My configuration is:
- MS SQL Server 2000 (SP3)
- SQL Server ODBC driver 2000.81.9042.00
- JDBC-ODBC-bridge sun.jdbc.odbc.JdbcOdbcDriver from JDK 1.4.2
- Hibernate 2.1.2

I have a very simple class with child/parent relationship where parents and childs are of the same class (ordinary tree structure):

public class TreeItemDTO {
private int id;
private String name;
private List childs;
private TreeItemDTO parent;

//getters and setters
}

The corresponding hbm-file is:
...
<class name="dox.enterprise.participant.organization.TreeItemDTO" table="treeitem" dynamic-update="false" dynamic-insert="false">
<id name="id" column="id" type="int">
<generator class="native">
</generator>
</id>

<property name="name" type="string" update="true" insert="true" column="name" length="64" not-null="true"/>

<bag name="childs" lazy="true" inverse="true" cascade="save-update">
<key column="parent_id"/>
<one-to-many class="dox.enterprise.participant.organization.TreeItemDTO"/>
</bag>

<many-to-one name="parent" class="dox.enterprise.participant.organization.TreeItemDTO" cascade="save-update"
outer-join="auto" update="true" insert="true" column="parent_id" not-null="false"/>
</class>
...

Inserting objects works fine!
But loading or quering throws an error (see debug output below):

...
Session s = ...;
TreeItemDTO item = new TreeItemDTO();
s.load(item, new Integer(1)); //-> throws HibernateException
...

I've run the following additional tests:
- Removed any foreign and primary key contraints from the database-table -> no effect.
- The whole thing works fine when using a MySQL-database instead of the MS SQL Server.
- I've removed the child/parent relation (childs and parent member) from my class -> now the load works


Thanks for any help!



Here's the debug output:
INFO: starting query cache at region: net.sf.hibernate.cache.QueryCache
Hibernate: select treeitemdt0_.id as id1_, treeitemdt0_.name as name1_, treeitemdt0_.parent_id as parent_id1_, treeitemdt1_.id as id0_, treeitemdt1_.name as name0_, treeitemdt1_.parent_id as parent_id0_ from treeitem treeitemdt0_ left outer join treeitem treeitemdt1_ on treeitemdt0_.parent_id=treeitemdt1_.id where treeitemdt0_.id=?
24.02.2004 13:56:10 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: S1002
24.02.2004 13:56:10 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: [Microsoft][ODBC SQL Server Driver]Ung


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 9:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The JDBC-ODBC bridge is really not good. Why don't you use a real Type4 JDBC driver like for example http://jtds.sourceforge.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 10:15 am 
Newbie

Joined: Fri Feb 20, 2004 7:37 am
Posts: 12
jTDS is JDBC 2.0 only so it won't support blobs, will it?

(By the way: I'm not sure if the JDBC-ODBC-bridge does either?!)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 10:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
JDBC 2.0 has BLOB support, and so does JTDS as far as I know


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 10:28 am 
Newbie

Joined: Fri Feb 20, 2004 7:37 am
Posts: 12
I'll give it a try.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 11:00 am 
Newbie

Joined: Fri Feb 20, 2004 7:37 am
Posts: 12
There are other problems with jTDS:
- The session.load(...) works.
- But now the insert fails!

...
Session s = ...;
TreeItemDTO item = new TreeItemDTO();
TreeItemDTO child = new TreeItemDTO();

item.setName("Parent");
child.setName("Child");
child.setParent(item);
Transaction tx = s.beginTransaction();
s.save(item); //-> throws the exception below
s.save(child);
tx.commit();
...

Hibernate: insert into treeitem (name, parent_id) values (?, ?) select SCOPE_IDENTITY()
24.02.2004 15:59:32 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: null
24.02.2004 15:59:32 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Was expecting a result set
24.02.2004 15:59:32 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: null
24.02.2004 15:59:32 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Was expecting a result set
24.02.2004 15:59:32 net.sf.hibernate.JDBCException <init>
SCHWERWIEGEND: could not insert: [dox.enterprise.participant.organization.TreeItemDTO]
java.sql.SQLException: Was expecting a result set
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeQuery(PreparedStatement_base.java:214)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:508)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:432)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:906)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:839)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:757)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:720)
at dox.enterprise.test.LowLevelDbTest.testTreeItem(LowLevelDbTest.java:37)
at dox.enterprise.test.LowLevelDbTest.main(LowLevelDbTest.java:102)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 11:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This was allready covered here: http://forum.hibernate.org/viewtopic.php?t=928086&highlight=expecting+result+set


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.