-->
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.  [ 3 posts ] 
Author Message
 Post subject: Inheritance and composite id mapping problem
PostPosted: Mon Sep 06, 2010 5:16 am 
Newbie

Joined: Mon Sep 06, 2010 4:19 am
Posts: 2
Hi

This is my first post on this forum so I would like to say HI to EVERYBODY.

I have classes (listed below). After run the MappingException is thrown:
Quote:
Foreign key (FK393AF2E2895B615:text_language_value_impl1 [language])) must have same number of columns as the referenced primary key (text_language_value [text_id,language])

Could anyone tell me why, or what I'm doing wrong?

Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="texts")
public abstract class Text {
   @Id
   @Column(name="text_id", updatable=false, nullable=false)
   private long id;   
   
   @OneToMany(orphanRemoval=true, cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
   @JoinColumn(name="text_id")
   private List<TextLanguageValue> languageTexts = new ArrayList<TextLanguageValue>();

   String description;

   protected Text(){}
...
}


Code:
@Entity
@Table(name="obj1_texts")
public class TextImpl1 extends Text {
   
   private TextImpl1(){
      super();
   }

   

}


Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="text_language_value")
public abstract class TextLanguageValue implements Serializable {

   @Id
   @ManyToOne(optional=false, cascade=CascadeType.ALL, fetch=FetchType.LAZY)
   @JoinColumn(name="text_id")
   private Text text;
   @Id
   @Column(name="language")
   private String language;
   
   private String value;
   
   protected TextLanguageValue(){
   }
   
   
   public TextLanguageValue(Text text, String language) {
      super();
      this.text = text;
      this.language = language;
   }

protected abstract TextLanguageValue createTextLanguageValue(String language);

public TextLanguageValue getLanguageText(String language){
      for (TextLanguageValue languageText : languageTexts) {
         if(languageText.getLanguage().equals(language))
            return languageText;
      }
      TextLanguageValue languageText = createTextLanguageValue(language);
      this.languageTexts.add(languageText);
      return languageText;
   }
...
}


Code:
@Entity
@Table(name="text_language_value_impl1")
public class TextLanguageValueImpl1 extends TextLanguageValue {

   private TextLanguageValueImpl1(){
      super();
   }
   
   public TextLanguageValueImpl1(Text text, String language) {
      super(text, language);
   }
   
}


Regards servee


Top
 Profile  
 
 Post subject: Re: Inheritance and composite id mapping problem
PostPosted: Mon Sep 06, 2010 5:46 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Hi Servee,

Table text_language_value_impl1 does not have 2 primary columns.

Since it inherited from text_language_value , text_id might be missing in inherited table.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Inheritance and composite id mapping problem
PostPosted: Tue Sep 07, 2010 4:22 am 
Newbie

Joined: Mon Sep 06, 2010 4:19 am
Posts: 2
Thank you very much for the clue.
You have right, i forgot to add annotation @IdClass to TextLanguageValue class (this class have composite id).

Thank you ones again
regards
servee


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