-->
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: Embedded objects in base class inaccessible via subclass
PostPosted: Thu Sep 06, 2007 12:43 pm 
Newbie

Joined: Tue Jun 19, 2007 9:21 am
Posts: 2
Location: UK
Hi,

I've come across an issue with the combination of embedded objects and inheritance. Given a parent class :

Code:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DISCRIM", discriminatorType = DiscriminatorType.STRING)
public abstract class Ape {

    private Long _id;
    private Head _head;

    public Ape() {
        _head = new Head();
    }

    @Id
    public Long getId() {
        return _id;
    }

    public void setId(Long id) {
        _id = id;
    }

    @Embedded
    public Head getHead() {
        return _head;
    }

    public void setHead(Head head) {
        _head = head;
    }

}


and the embeddable class

Code:

@Embeddable
public class Head {
    private String _eyeColour;
    private Long _numberOfTeeth;

    public Head() {
        _eyeColour = "Blue";
        _numberOfTeeth = 20l;
    }

    @Column(name = "EYE_COLOUR", nullable = false)
    public String getEyeColour() {
        return _eyeColour;
    }

    public void setEyeColour(String eyeColour) {
        _eyeColour = eyeColour;
    }

    @Column(name = "NUMBER_OF_TEETH", nullable = false)
    public Long getNumberOfTeeth() {
        return _numberOfTeeth;
    }

    public void setNumberOfTeeth(Long numberOfTeeth) {
        _numberOfTeeth = numberOfTeeth;
    }

}



with, of course, the appropriate backing table, I can define various subclasses. One will suffice :

Code:

@Entity
@DiscriminatorValue("MONKEY")
public class Monkey extends Ape{

    private Long _leapingHeight;

    public Monkey() {
        super();
    }

    @Column(name = "LEAPING_HEIGHT", nullable = false)
    public Float getLeapingHeight() {
        return _leapingHeight;
    }

    public void setLeapingHeight(Float leapingHeight) {
        _leapingHeight = leapingHeight;
    }

}



Anyway, if I create and save a Monkey, I can either retrieve by doing :

Code:
session.load(Monkey.class, monkeyId)
or
Code:
session.load(Ape.class, monkeyId)


Both of these work and, obviously, I can cast either to an Ape object. However, even though both Monkey and Ape should have access to the Head property, only the second of the two lookups works. The first, when you have retrieved the subclass, fails with a

Code:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [Monkey#0]


Does anyone have any idea what I might be doing wrong? There is nothing in the literature saying that an embedded property on a parent is not accessible from a subclass.

Hope someone with the Hibernate magic can shed some light on this :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 07, 2007 5:43 am 
Newbie

Joined: Tue Jun 19, 2007 9:21 am
Posts: 2
Location: UK
Inexplicably, probably due to a shuffling of libraries, this use case now works. I will post what caused this if I figure it out :P


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.