-->
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: Table per class hierarchy and many-to-one associations
PostPosted: Tue May 15, 2007 7:08 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Hibernate version:
Was 3.0.5, is now 3.2.1. Since upgrading, objects loaded via many-to-one associations cannot be deproxied. I'm thinking it's because lazy="true" has been replaced, but I've tried all three values of that attribute, and it affects them all.

Loading AbstractLoggers directly works fine, I get ETypeLoggers and MTypeLoggers as appropriate. Via many-to-ones, I get AbstractLoggers (the abstract base class), and no amount of property-accessing, Hibernate.initialize()ing, or anything else that I can think of, works. My next step is to eliminate polymorphism, and put all properties into a non-abstract class. Not ideal, so I'm hoping someone spots my error.

Mapping documents:
The big weirdness here is that the discriminator column isn't in the mapped table, it's in an associated type table. Loggers have LoggerTypes, LoggerTypes have an AMRTypeID column, and the two values of that column determine the class of the Logger.
Code:
  <class name="LoggerType" table="MeterType" mutable="false">
    ...
    <property name="AMRType" column="AMRTypeID">
      <type name="IntValuedEnum">
        <param name="enum">
          ...AMRType
        </param>
      </type>
    </property>
    ...
  </class>

  <class name="AbstractLogger" table="Logger" mutable="true" abstract="true"
    discriminator-value="null">
    ...
    <discriminator type="character" insert="false"
      formula="
        case when LoggerTypeID in
         (select mt.MeterTypeID from MeterType mt
            where mt.AMRTypeID = '1')
         then 'E'
         else 'M'
       end"/>

    <many-to-one name="Type" class="LoggerType"
      unique="false" not-null="true"
      column="LoggerTypeID"/>

    ...

    <subclass name="ETypeLogger" discriminator-value="E"/>

    <subclass name="MTypeLogger" discriminator-value="M">
      <property name="MemorySize" column="MemorySize" type="integer"/>
      ...
    </subclass>
  </class>


Any many-to-one from any other class to AbstractLogger exhibits the symptoms.

_________________
Code tags are your friend. Know them and use them.


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.