-->
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: load(Parent.class,id) does not load child class correctly
PostPosted: Thu Nov 02, 2006 11:49 am 
Regular
Regular

Joined: Thu Oct 19, 2006 12:07 pm
Posts: 75
hibernate-3.2
MySQL 4.1

Code:
     Parent parent1 = (Parent) session.load(Parent.class, id);
      System.err.println("object is : " + parent1);
      if (parent1 instanceof Child)
      {
        System.err.println("It is a Child!");
      }

This does NOT print "It is a Child!" , even if the object is a Child.
It just prints "I'm a Child, ...." (see below).


Defs :

Code:
public class Child extends Parent
{
   String foo; // some property
...
  public String toString()
  {
    return "I'm a Child, "+super.toString()+"\n foo:" + foo+ ...;
  }

}


Mapping :

Code:
<hibernate-mapping package="com.foo.bar.ix">
   <class name="Parent">
      <id name="id">
         <generator class="native" />
      </id>
      <property name="foo"/>
      <property name="bar"/>

      <joined-subclass name="Child">
         <key />
         <property name="foo"/>
      </joined-subclass>
   </class>

If I change the first line to
<hibernate-mapping package="com.foo.bar.ix" default-lazy="false"> then it works as expected.

Any idea how to make work with lazy fetching too ?

Regards,
David


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.