-->
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.  [ 1 post ] 
Author Message
 Post subject: joined-subclass query returning parent class for subclass
PostPosted: Fri Jan 08, 2016 1:36 pm 
Newbie

Joined: Fri Jan 08, 2016 1:23 pm
Posts: 1
I had a model that included a table called bpl_repository that mapped to a RepositoryBean.

I created two new subclasses of this repository: bpl_domerepository which maps to DOMERepositoryBean and bpl_lfsrepository which maps to LFSRepositoryBean.


Code:
<class name="com.polarlake.pl4edm.model.RepositoryBean" table="bpl_repository">

      <id type="long" access="field" name="id">
         <generator class="native">
            <param name="sequence">repository_sequence</param>
            <param name="max_lo">1000</param>
         </generator>
      </id>
      <version type="long" unsaved-value="null" access="field" name="version" />

      <property type="long" access="field" name="repositoryIdentifier"
         unique="true" />
      <property type="string" access="field" name="repositoryName" />
      <property type="string" access="field" name="repositoryType" />
      <property type="string" access="field" name="description" />
      <property name="status" access="field">
         <type name="org.hibernate.type.EnumType">
            <param name="enumClass">com.polarlake.pl4edm.model.RepositoryStatus</param>
            <param name="useNamed">true</param>
         </type>
      </property>

      <list table="bpl_repository_prop" access="field" name="repositoryProperties">
         <key column="repository_id" />
         <list-index column="idx" />
         <composite-element
            class="com.polarlake.pl4edm.model.RepositoryPropertyBean">
            <property name="name" type="string" access="field" />
            <property name="propertyValue" type="string" access="field" />
         </composite-element>
      </list>
      <joined-subclass name="com.polarlake.pl4edm.model.LFSRepositoryBean"
         table="bpl_lfsrepository">

         <key column="repository_id"></key>
         <property name="fileStoreQueryUrl" type="string" access="field"/>
         <property name="vendor" type="string" access="field" />

      </joined-subclass>

      <joined-subclass name="com.polarlake.pl4edm.model.DOMERepositoryBean"
         table="bpl_domerepository">
         <key column="repository_id"></key>
         <property name="databaseURL" type="string" access="field"/>
         <property name="username" type="string" access="field"/>
         <property name="password" type="string" access="field"/>

      </joined-subclass>
   </class>


I am having a strange problem with the discriminator when I try to resolve a LFSRepositoryBean that used to be a RepositoryBean before I made the changes. What I mean is that this doesn't occur for beans created after the model change and it doesnt occur at all for DOMERepositoryBeans.

When trying to resolve a LFSRepositoryBean by repositoryIdentifier e.g "11"

the following SQL is generated by hibernate:

Code:
SELECT repository0_.id              AS id1_3_,
  repository0_.version              AS version2_3_,
  repository0_.repositoryIdentifier AS reposito3_3_,
  repository0_.repositoryName       AS reposito4_3_,
  repository0_.repositoryType       AS reposito5_3_,
  repository0_.description          AS descript6_3_,
  repository0_.status               AS status7_3_,
  repository0_1_.fileStoreQueryUrl  AS fileStor2_2_,
  repository0_1_.vendor             AS vendor3_2_,
  repository0_2_.databaseURL        AS database2_1_,
  repository0_2_.username           AS username3_1_,
  repository0_2_.password           AS password4_1_,
  CASE
    WHEN repository0_1_.repository_id IS NOT NULL
    THEN 1
    WHEN repository0_2_.repository_id IS NOT NULL
    THEN 2
    WHEN repository0_.id IS NOT NULL
    THEN 0
  END AS clazz_
FROM bpl_repository repository0_
LEFT OUTER JOIN bpl_lfsrepository repository0_1_
ON repository0_.id=repository0_1_.repository_id
LEFT OUTER JOIN bpl_domerepository repository0_2_
ON repository0_.id                     =repository0_2_.repository_id
WHERE repository0_.repositoryIdentifier=11;


The Query result has the value "1" for clazz_ which shows that it exists in bpl_lfsrepository so should be a LFSRepositoryBean.

What is happening is that the discriminator value being resolved is "0".

I have located the code that resolves the discriminator value but I couldn't figure out why it is resolving to 0 if clazz_ is 1.

org.hibernate.loader.Loader line 1730

Code:
         // Code to handle subclasses of topClass
         Object discriminatorValue = persister.getDiscriminatorType().nullSafeGet(
               rs,
               getEntityAliases()[i].getSuffixedDiscriminatorAlias(),
               session,
               null
            );



Any help is appreciated


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

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.