嗨我想創建一個到多個關係與字符串對象與同一個表上的不同的密鑰ID。休眠GenericJDBCException:字段'KeyID'沒有默認值
但是當我插入的數據會顯示異常「從服務器一般錯誤消息:‘字段‘QID’沒有缺省值’
如何解決休眠問題,請參考。下面的代碼
<class name="com.db.HRQuestion" table="HRQuestion">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="qname"></property>
<list name="answers" table="answer">
<key column="qid"></key>
<index column="type"></index>
<element column="answer" type="string"></element>
</list>
</class>
<class name="com.db.JavaQuestion" table="javaQuestion">
<id name="id">
<generator class="increment"></generator>
</id>
<property name="qname"></property>
<list name="answers" table="answer">
<key column="java_qid"></key>
<index column="type"></index>
<element column="answer" type="string"></element>
</list>
</class>
Java代碼是:
JavaQuestion javaQuestion= new JavaQuestion();
javaQuestion.setQname("What is meant by java?");
ArrayList<String> javaanswerlist=new ArrayList<String>();
javaanswerlist.add("java is Object oriented programming ");
javaanswerlist.add("java is a platform independent");
javaQuestion.setAnswers(javaanswerlist);
HRQuestion hrquestion=new HRQuestion();
hrquestion.setQname("Hr Question one");
ArrayList<String> list2=new ArrayList<String>();
list2.add("My profile .....");
list2.add("My objetcive...");
hrquestion.setAnswers(list1);
session.save(javaQuestion);
session.save(hrquestion);