-->
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.  [ 10 posts ] 
Author Message
 Post subject: I cannot get a serialized object from database
PostPosted: Thu Jul 22, 2004 11:03 am 
Newbie

Joined: Thu Jul 22, 2004 10:39 am
Posts: 7
Location: France
Hello Everyone,

I encounter a problem with Hibernate 2.1.2, jdk1.4 and Oracle 9.2.0.1.
I have a class containing a mapped collection of objects retrieved using the <map> tag in my hibernate_mapping.xml (here is the code)

Code:
  <class table="CB_TEMPLATES" name="com.cardiweb.cardibox.contentmanagement.Template">
        <id type="long" column="ID_TEMPLATE" name="id" unsaved-value="-1">
            <generator class="com.cardiweb.cardibox.components.persistence.HibernateIdGenerator"/>
        </id>
        <property not-null="true" type="timestamp"  column="CREATION_DATE"      name="createdTimestamp"/>
        <property not-null="true" type="timestamp"  column="MODIFICATION_DATE"  name="modifiedTimestamp"/>
        <property not-null="true" type="string"     column="name"               name="name"/>
        <property not-null="true" type="string"     column="description"        name="description"/>
        <property not-null="true"   type="string"      column="SHORTCUT"         name="shortcut"/>
        <property not-null="true" type="serializable"   column="code"       name="code"/>
        <property not-null="true" type="serializable"   column="preview"    name="preview"/>
        <map name="tags" table="cb_template_tags">
           <key column="id_template"/>
           <index column="tagname" type="string"/>
           <element column="tag" type="serializable"/>
        </map>
    </class>


Everything is ok when I save data to the database.

The problem occurs when I try to get the collection.
The debugger tells me the first part of the object is OK.
But an Exception is thrown when reading the resulset mapping the collection.

Here is the debug log :

[code]
[DEBUG][ SessionImpl][22/07][16:38:04] initializing collection [com.cardiweb.cardibox.contentmanagement.Template.tags#143881672272642048]
[DEBUG][ SessionImpl][22/07][16:38:04] checking second-level cache
[DEBUG][ SessionImpl][22/07][16:38:04] collection not cached
[DEBUG][ BatcherImpl][22/07][16:38:04] about to open: 0 open PreparedStatements, 0 open ResultSets
[DEBUG][ SQL][22/07][16:38:04] select tags0_.tag as tag__, tags0_.id_template as id_templ4___, tags0_.tagname as tagname__ from cb_template_tags tags0_ where tags0_.id_template=?
Hibernate: select tags0_.tag as tag__, tags0_.id_template as id_templ4___, tags0_.tagname as tagname__ from cb_template_tags tags0_ where tags0_.id_template=?
[DEBUG][ BatcherImpl][22/07][16:38:04] preparing statement
[DEBUG][ LongType][22/07][16:38:04] binding '143881672272642048' to parameter: 1
[DEBUG][ Loader][22/07][16:38:04] result set contains (possibly empty) collection: [com.cardiweb.cardibox.contentmanagement.Template.tags#143881672272642048]
[DEBUG][ SessionImpl][22/07][16:38:04] uninitialized collection: initializing
[DEBUG][ Loader][22/07][16:38:04] processing result set
[DEBUG][ Loader][22/07][16:38:04] result row:
[DEBUG][ LongType][22/07][16:38:04] returning '143881672272642048' as column: id_templ4___
[DEBUG][ Loader][22/07][16:38:04] found row of collection: [com.cardiweb.cardibox.contentmanagement.Template.tags#143881672272642048]
[DEBUG][ SessionImpl][22/07][16:38:07] reading row
[DEBUG][ JDBCExceptionReporter][22/07][16:38:13] SQL Exception
java.sql.SQLException: Le flux de donn


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 11:49 am 
Newbie

Joined: Thu Jul 22, 2004 10:39 am
Posts: 7
Location: France
In addition, the translation of the Exception (java.sql.SQLException: Le flux de donn


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 11:59 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
The issue is an Oracle JDBC driver issue. I believe the serialized object MUST be the LAST thing that you fetch in your fetch. However, it would appear you are fetching 2 serializable objects and are hooped. :)

From the searching we did on it a few weeks back when we encountered the problem, it seems as if it has been around since at least 1999. There is at least one other post on these forums that references it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 12:11 pm 
Newbie

Joined: Thu Jul 22, 2004 10:39 am
Posts: 7
Location: France
The object that causes the problem is the tag element of the <map> part of the <class> in my hibernate_mapping.xml file
Code:
        <map name="tags" table="cb_template_tags">
           <key column="id_template"/>
           <index column="tagname" type="string"/>
           <element column="tag" type="serializable"/>
        </map>


It is declared last in the xml file and in the database (same order).
But the order of the SQL select statement generated by Hibernate is the following :
tag, id_template, tagname

Do I have a way to force Hibernate to select the columns and fetch them in the database order ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 1:20 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Just for giggles, does it work if you remove the map?

I would think simply having

Code:
       <property not-null="true" type="serializable"   column="code"       name="code"/>
        <property not-null="true" type="serializable"   column="preview"    name="preview"/>
.


would cause you grief as well


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 3:48 am 
Newbie

Joined: Thu Jul 22, 2004 10:39 am
Posts: 7
Location: France
Hi,

I have that case in another table and it seems I have no problem with it.

It looks like it only happens with "sub-collections".

I already tried to change the mapping, change the order of the table, change the Oracle JDBC driver (I tested almost all driver for version 9i) but the result is always the same.

Another point:
That application was running on Oracle 8i and Hibernate 1.2 without problem.

Has something changed in the way of selecting and fetching rows in Hibernate 2 ?
And I ask my previous question again :
Is there a way to force Hibernate to select the columns and fetch them in the database order ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 11:52 am 
Newbie

Joined: Thu Jul 22, 2004 10:39 am
Posts: 7
Location: France
We now know precisely what goes wrong.
Using Oracle and a table that contains a serializable object, you MUST
fetch the data in the columns exactly in the same order as you select them.
Which means that when the query is 'SELECT A,B,C from...', when parsing the
resultset , you have to retrieve first column A then B then C.
Hibernate, in the case of a map does not do that.

Looking at the Debug log of hibernate, the select statement look like this
(according to hibernate_mapping.xml) :

select <element>, <key>, <index> from mytable

when the hibernate mapping is:

Code:
<map name="tags" table="cb_template_tags">
<key column="id_template"/>
<index column="tagname" type="string"/>
<element column="tag" type="serializable"/>
</map>


Then Hibernate parses the resultset in the follwing order:
<key>, <element>, <index>
which is different.

That causes the problem.
For your information, I have another similar case in my application, but
without serializable object, and it works fine because in that case the
read/select order
doesn't matter.

Is there a way to fix the read/select order ? Do I have to open a bug
report in JIRA ?

thanks for your help !


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
open a JIRA issue, if you want.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 2:31 pm 
Newbie

Joined: Mon Jul 26, 2004 2:19 pm
Posts: 6
Hi there,

unfortunately we have observed the same problem under Bea Weblogic 8.1SP2. We have switched to Bea's own JDBC driver and could tackle the problem that way. You can read some details how to integrate Bea's driver at

[http://e-docs.bea.com/wls/docs81/jdbc_drivers/oracle.html#1057693]

However, we would still prefer a solution working under Oracle's driver.

Have Fun

Dokmatik


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 10:45 am 
Newbie

Joined: Thu Jul 22, 2004 10:39 am
Posts: 7
Location: France
I opened a JIRA issue and it is now fixed for versions 2.1.5 and future Hibernate 3.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.