-->
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: Subclassing & overriding getter method - possible?
PostPosted: Fri Jul 04, 2008 9:54 am 
Newbie

Joined: Fri Jul 04, 2008 9:39 am
Posts: 2
Hi,

I'm trying to do something that seems simple, but is causing me grief...

I'm trying to set up:
* A class that is a hibernate entity, using annotations, with getters and setters (perfectly normal).
* A second class that subclasses this class, and overrides one of the getters.

Unfortunately, the problem I have is:
* If I override the getter, and put no annotations on it, hibernate tries to treat the property name as a column name, instead of using the annotation on the true getter in the superclass.
* If I add in a column annotation, Hibernate tells me 'repeated column name'.

For example:
Code:
    @Entity
    @Table(name = "TestBean")
    @DiscriminatorColumn(name = "DiscrimCol",discriminatorType = DiscriminatorType.INTEGER)
    @DiscriminatorValue("1")
    public class TestSuperBean
    {
        private long    cSeq;
        private String  cID;
       
        public TestSuperBean()
        {
           
        }

        @Id @GeneratedValue
        @Column(name = "TestBeanSeq")
        public long getSeq()
        {
            return(cSeq);
        }

        public void setSeq(long seq)
        {
            cSeq = seq;
        }

        @Column(name = "TestBeanID")
        public String getID()
        {
            return(cID);
        }

        public void setID(String id)
        {
            cID = id;
        }
    }

    @Entity
    @DiscriminatorValue("2")
    public class TestSubBean extends TestSuperBean
    {

        @Column(name = "TestBeanID")
        public String getID()
        {
            return(super.getID());
        }
    }


In the above, if I leave off the @Column (in the subclass), I get an error attempting to write to a column named 'ID'. If I put the annotation ON, I get the 'repeated column' error.

I know I could take the annotation out of the superclass, and only put it in the subclass, but it seems silly that I would have to jump through hoops -- I really want hibernate to recognize that this is overridden, and behave appropriately.

I can't seem to find any references to this kind of thing anywhere -- is this even possible?

TIA for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:14 am 
Newbie

Joined: Fri Jul 04, 2008 9:39 am
Posts: 2
Hmm, OK here is the weird thing...

I *can* do this if I annotate the instance variable, not the getter.

This makes this seem more like a hibernate bug...


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.