Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate inheritence problem

 
waqas shahwar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am facing some problem with inheritence table per subclass
My Questionaire Class uses it's primary key questionaire_id
in the Abstract class Question MultipleChoiceQuestion class extends Question class but the problem is when I insert into questionire that works fine but when I insert into MCSSQuestion class it doesnot insert.Could anyone knows this problem?
Here is source code
lecturer1=new Lecturers("Alan","asdf","asnd","xyz@cs.ac.bham.uk","asd");
questionaire1 = new Questionaire(lecturer1,"ISSWorkShop");
Question mcss1=new MCSSQuestion(questionaire1,"what is java");
session.save(lecturer1);


<class name="Questionaire" table="questionaire">
<id name="id" column="qaireid">
<generator class="sequence"/>
</id>
<natural-id mutable="false">
<property name="Title" column="_title"/>
<many-to-one name="lecturer" class="Lecturers" cascade="none" column="lecturer"/>
</natural-id>
<version name="version" column="version"/>
<list name="mcssquestion" cascade="all-delete-orphan" lazy="true">
<key column="questionaireID" not-null="true"/>
<list-index column="position"/>
<one-to-many class="Question"/>
</list>
</class>


<class name="Question" table="_Question">
<id name="questionid" column="QuestionID">
<generator class="native"/>
</id>
<many-to-one name="questionaireid" class="Questionaire" not-null="true" insert="false" update="false" cascade="none" column="_questionaire"/>

<joined-subclass name="MCSSQuestion" table="_mcQuestion">
<key column="QuestionID"/>
<property name="questiontext" column="_questiontext"/>
<property name="version" column="version"/>
</joined-subclass>
</class>

Here is java source code
public abstract class Question
{

/** Creates a new instance of Question */
private int questionid;
private int question_postion;
private Questionaire questionaireid;
private int version;
public Question()
{

}

public int getQuestionid()
{
return questionid;
}

public void setQuestionid(int questionid)
{
this.questionid = questionid;
}

public int getQuestion_postion()
{
return question_postion;
}

public void setQuestion_postion(int question_postion)
{
this.question_postion = question_postion;
}

public Questionaire getQuestionaireid()
{
return questionaireid;
}

public void setQuestionaireid(Questionaire questionaireid)
{
this.questionaireid = questionaireid;
}

public int getVersion()
{
return version;
}

public void setVersion(int version)
{
this.version = version;
}

}
public class MCSSQuestion extends Question implements Serializable
{

/** Creates a new instance of MCSSQuestion */
private Long questionID;
private String questiontext;
private int version; // private int options;
//private Questionaire questionaire;
//private String Ans[];
//private int correctAns;
// private List<Answer> answer=new LinkedList<Answer>();
public MCSSQuestion()
{

}

public MCSSQuestion(Questionaire q,String _questiontext)
{
this.setQuestiontext(_questiontext);
super.setQuestionaireid(q);

// this.questionaire=questionaire;

//this.setAns(answers);
// this.setCorrectAns(_correctAns);
// this.options=_options;
// questionaire.addMCSSQuestion(this);
}

public Long getId()
{
return getQuestionID();
}

public void setId(Long id)
{
this.setQuestionID(id);
}

public String getQuestiontext()
{
return questiontext;
}

public void setQuestiontext(String questiontext)
{
this.questiontext = questiontext;
}
public Long getQuestionID()
{
return questionID;
}

public void setQuestionID(Long questionID)
{
this.questionID = questionID;
}
 
Shailesh Kini
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Waqas,

Can you add any exceptions/stack trace you get to this post?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic