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!