java - Hibernate GenericJDBCException : Field 'KeyID' doesn't have a default value -
hi trying create 1 many relationship string object different key id on same table.
but when insert data show exception "general error message server: "field 'qid' doesn't have default value".
how resolve problem in hibernate. please refer below code.
<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 code :
javaquestion javaquestion= new javaquestion(); javaquestion.setqname("what meant java?"); arraylist<string> javaanswerlist=new arraylist<string>(); javaanswerlist.add("java object oriented programming "); javaanswerlist.add("java 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);
as map 2 lists of answers same table, have define both key column qid
, java_qid
nullable.
<key column="qid" not-null="false"></key> .... <key column="java_qid" not-null="false"></key>
Comments
Post a Comment