-->
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: Inheritance and overriding
PostPosted: Mon Nov 26, 2007 10:48 am 
Newbie

Joined: Mon Jun 12, 2006 5:26 am
Posts: 3
Hi,

I have an inehritance/overriding problem and I didn't find any solution on docs or internet.

Hibernate version:
core: 3.2.4-sp1
annotations: 3.3.0

Hi, I have these 3 classes:

Code:
@Entity
public class Father {

    private int id;
    private String comment;

    @Id
    public int getId() {
        return id;
    }

    public String getComment() {
        return comment;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    @Override
    public String toString() {
        return getClass().getName() + "-> id:" + getId() + ", comment:" + getComment();
    }
}

-------------------------------------------------------------------------------------
@Entity
public class Child extends Father {
}
-------------------------------------------------------------------------------------
@Entity
public class OverridenChild extends Father {

    @Override
    public String getComment() {
        return super.getComment();
    }

    @Override
    public void setComment(String comment) {
        super.setComment(comment);
    }

}


In the OverridenChild class, I want to override the comment property (for adding code or a validator annotation).
If I don't put a @Transient annotation on getComment(), I get the following exception:
Code:
Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: org.test.OverridenChild column: comment (should be mapped with insert="false" update="false")
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:652)
   at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:674)
   at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:450)
   at org.hibernate.mapping.SingleTableSubclass.validate(SingleTableSubclass.java:43)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
   at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
   at org.test.Test.<clinit>(Test.java:29)


If I put an @OverrideAttribute on comment, Hibernate complain that I'm trying to register the column comment 2 times.

It's very odd to need to add an @Transient annotation on a persistent property. Am'I missing something?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 28, 2007 2:22 pm 
Newbie

Joined: Mon Jun 12, 2006 5:26 am
Posts: 3
Am I alone using inheritence?


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.