-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems using a SQL Server stored procedure for loading
PostPosted: Fri Jul 04, 2008 2:24 am 
Newbie

Joined: Fri Jul 04, 2008 1:55 am
Posts: 2
Hi,

We need to have a class which depending of one parameter has to be stored in different tables. Because of this we need to write custom sql for loading. This sql will be a MS SQL Server stored procedure.
Somewhere we make an error in our mapping. I can see in the log files, Hibernate loads the object from the database.

Code:
quadeo.indexv2.IndexTagOccurrenceV2{srcType=quadeo.indexv2.IndexTagSrcTypeV2#1, id=4, order=1, tag=quadeo.indexv2.IndexTagV2#1, tagSpell=quadeo.indexv2.IndexTagSpellV2#3, srcObjId=99}



However, the call to
hibSession.get(IndexTagOccurrenceV2.class, id)
returns null, I don't understand why.

The mapping we use looks like this:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="quadeo.indexv2">
   <class name="IndexTagOccurrenceV2">

      <id name="id" column="IDXTAGOCCURR_ID">
         <generator class="native"/>
      </id>

      <many-to-one name="tag" class="IndexTagV2" index="IDXTAGOCCURR_IDXTAG_ID">
            <column name="IDXTAGOCCURR_IDXTAG_ID"/>
        </many-to-one>

      <many-to-one name="srcType" class="IndexTagSrcTypeV2" index="IDXTAGOCCURR_IDXTAGSRCTYP_ID">
            <column name="IDXTAGOCCURR_IDXTAGSRCTYP_ID"/>
        </many-to-one>

      <property name="srcObjId" column="IDXTAGOCCURR_SRC_OBJ_ID" not-null="true"/>

      <many-to-one name="tagSpell" class="IndexTagSpellV2" index="IDXTAGOCCURR_IDXTAGSPELL_ID">
            <column name="IDXTAGOCCURR_IDXTAGSPELL_ID"/>
        </many-to-one>
      <property name="order" column="IDXTAGOCCURR_ORDER" not-null="true"/>

      <loader query-ref="load_tag_occur"/>
   </class>

   <sql-query name="load_tag_occur">
      <return class="quadeo.indexv2.IndexTagOccurrenceV2"/>

      {call spLoadIndexTagOccurrence(?)}
   </sql-query>

</hibernate-mapping>



The MS SQL Server stored procedure is just dummy, gets the id as a parameter and (for testing) selects from a random table:

Code:
ALTER PROCEDURE [dbo].[spLoadIndexTagOccurrence]
   @id nvarchar(50)
AS
BEGIN
   SET NOCOUNT ON;
   select IDXTAGOCCURR_ID, IDXTAGOCCURR_IDXTAG_ID,  IDXTAGOCCURR_IDXTAGSRCTYP_ID, IDXTAGOCCURR_SRC_OBJ_ID, IDXTAGOCCURR_IDXTAGSPELL_ID from quadeo_index_tags_occurrences_XXX occur
END


Do we do something wrong here?
Why do we get a null from the call

hibSession.get(IndexTagOccurrenceV2.class, id) ?


Thank you very much!


Top
 Profile  
 
 Post subject: Problem solved :-)
PostPosted: Fri Jul 04, 2008 2:51 am 
Newbie

Joined: Fri Jul 04, 2008 1:55 am
Posts: 2
The problem was that the call, got as a parameter a string which has a special logical meaning and has to be parsed.

hibSession.get(IndexTagOccurrenceV2.class, id)

Everything worked fine, but the select from the database didn't send back the same string in the id column. It just sent back a part of it.

Hibernate simply didn't like it and just got me null back.

Thank you anyway to all those which tried to help.


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