-->
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.  [ 4 posts ] 
Author Message
 Post subject: Override mappedBy onetomany annotation from mappedsuperclass
PostPosted: Mon Apr 30, 2007 6:10 pm 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
Hi everybody

I have implemented an abstract MappedSuperclass that defines a OneToMany property. I want in subclases to override the "mappedBy" attribute of the OneToMany annotation, so

Code:
@MappedSuperclass
public abstract class BasePersistentObjectTranslateable<T, X extends Translation> extends BasePersistentObject<T> {
   
    @OneToMany()
    protected List<X> translations;
   

    public List<X> getTranslations() {
        return translations;
    }

   
    public void setTranslations(List<X> translations) {
        this.translations = translations;
    }
}


Code:
@Entity()
@Table(name="Cities")
public class City extends BasePersistentObjectTranslateable<City, CityTranslation> {
   
    // This is the wanted annotation
    // @OneToMany(mappedBy="city")
    // protected List<CityTranslation> translations;
   
   
}


Code:
@MappedSuperclass
public abstract class Translation extends BasePersistentObject<Translation> {
   
   
    @ManyToOne()
    @JoinColumn(name="LanguageId")
    protected Language language;
   
    @Column(name="TranslatedText")
    protected String translatedText;
   
    /** Creates a new instance of Translation */
    public Translation() {
    }


    public Language getLanguage() {
        return language;
    }

    public void setLanguage(Language language) {
        this.language = language;
    }

    public String getTranslatedText() {
        return translatedText;
    }

    public void setTranslatedText(String translatedText) {
        this.translatedText = translatedText;
    }
   
}


Code:
@Entity()
@Table(name="CitiesTranslations")
public class CityTranslation extends Translation {
   
    @ManyToOne()
    @JoinColumn(name="CityId")
    private City city;
   
    /** Creates a new instance of CityTranslation */
    public CityTranslation() {
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

}


Tha target of all this, is to have the translation of the cities in some languages, so a City or a Country has a collection of translations, and a CityTranslation or a CountryTranslation has a City or a Country, but a CityTranslation has a mappedBy="city" and a CountryTranslation has a mappedBy="country".

Any idea? Thanks in advance.

Hibernate version:3.2.3


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 5:51 am 
Newbie

Joined: Thu Jun 22, 2006 7:19 am
Posts: 14
No idea? Thereis no much documentation about @AttibuteOverride and @AssociationOverride...


Top
 Profile  
 
 Post subject: Re: Override mappedBy onetomany annotation from mappedsuperclass
PostPosted: Fri May 07, 2010 3:23 pm 
Newbie

Joined: Wed Jul 28, 2004 4:17 pm
Posts: 2
Hi,
I know this tread is old but I'm looking for a solution to this problem, thank you,


Top
 Profile  
 
 Post subject: Re: Override mappedBy onetomany annotation from mappedsuperclass
PostPosted: Fri Nov 02, 2012 7:44 am 
Newbie

Joined: Mon Jul 30, 2007 5:03 am
Posts: 8
I know it's a really old thread but it is exactly the problem I am facing. Does anyone have an idea?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.