-->
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: "Table per class hierarchy" objects loading proble
PostPosted: Sat Dec 16, 2006 8:54 pm 
Newbie

Joined: Sat Dec 16, 2006 8:42 pm
Posts: 1
Here is a mapping file, which describes the hierarchy of two classes
Code:
<?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="prkm.wssup.db.persistance">

    <class name="JarObject" table="jar_object">
        <id name="id" column="id" type="integer">
            <generator class="native"/>
        </id>

       <discriminator column="service_jar" type="string" />       

      <property name="jarName" column="jar_name" type="string" not-null="true" />
      
      <property name="originName" column="origin_name" type="string" not-null="true" />

      <property name="description" column="description" type="string" not-null="false" />      

      <many-to-one name="user" column="user_id" class="User" not-null="true" lazy="false"/>      
       
        <!--Service class-->
      <subclass name="ServiceJarObject" discriminator-value="SRV">
         
         <set name="jarDepenededObjSet" cascade="save-update" lazy="true" >
             <key column="service_jar_id"/>
              <many-to-many class="LoadJarObject" column="load_jar_id"/>             
           </set>      
         
      </subclass>       

        <!--Load class-->
      <subclass name="LoadJarObject" discriminator-value="LOAD">

         <set name="jarDepenededObjSet" cascade="save-update" lazy="true">
             <key column="load_jar_id"/>
              <many-to-many class="ServiceJarObject" column="service_jar_id"/>
           </set>         
      </subclass>               
    </class>
</hibernate-mapping>

The objects are stored into the DB correctly, it mean that for each subclass is written its discriminator. The problems start when i load the objects from Db. For example, when i load the LoadJarObject objects, I recieve all records from table as LoadJarObject objects.
The SQL belove: the first - when i get all ServiceJarObject, and the second - LoadJarObject
Code:
Hibernate: select servicejar0_.user_id as user6_1_, servicejar0_.id as id1_, servicejar0_.id as id14_0_, servicejar0_.jar_name as jar3_14_0_, servicejar0_.origin_name as origin4_14_0_, servicejar0_.description as descript5_14_0_, servicejar0_.user_id as user6_14_0_ from jar_object servicejar0_ where servicejar0_.user_id=?

Hibernate: select loadjarobj0_.user_id as user6_1_, loadjarobj0_.id as id1_, loadjarobj0_.id as id14_0_, loadjarobj0_.jar_name as jar3_14_0_, loadjarobj0_.origin_name as origin4_14_0_, loadjarobj0_.description as descript5_14_0_, loadjarobj0_.user_id as user6_14_0_ from jar_object loadjarobj0_ where loadjarobj0_.user_id=?

I don't see any discriminators in the generated by Hibenate SQL. :-(
Can anybody help me? Thank you.[/code]


Top
 Profile  
 
 Post subject: Re: "Table per class hierarchy" objects loading proble
PostPosted: Wed May 23, 2012 11:20 am 
Newbie

Joined: Wed May 23, 2012 11:14 am
Posts: 1
in spite of this topic is rather old, maybe this information will be helpful to somebody.
to solve this problem just add attribute force="true" to the definition of discriminator column like this:
Code:
<discriminator column="service_jar" type="string" force="true"/>


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.