Hi all :)
I'm having a problem with an insertion not generating a primary key value for an entity. This is the only class in my application where this problem is happening, and I'm not sure why. The session factory, on configuration, reports no errors or warnings. The class has no problems on creation or during interaction with other persistent entities.
Here's the class's mapping:
Code:
<hibernate-mapping>
<class name="QuestionFeedback" table="users_trivia_game_questions_feedback">
<id name="userTriviaGameQuestionFeedbackId" type="int">
<column name="user_trivia_game_question_feedback_id"/>
<generator class="native"/>
</id>
<many-to-one name="question" column="question_id" class="Questions" not-null="true"/>
<many-to-one name="triviaGame" column="user_trivia_game_id" class="TriviaGame" not-null="true"/>
<many-to-one name="generalFeedback" column="general_feedback" class="FeedbackType" insert="false" update="false"/>
<property name="providedAnswer" type="int" column="provided_answer" not-null="true"/>
<property name="detailedFeedback" type="string" column="detailed_feedback"/>
</class>
</hibernate-mapping>
The relevant code that fails is this:
Code:
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
SinglePlayerGame triviaGame = (SinglePlayerGame)session.getNamedQuery("triviaGameById").setInteger("userTriviaGameId", m_TriviaGameId).uniqueResult();
...
int correctQuestions = 0;
Set<QuestionFeedback> gameFeedback = triviaGame.getQuestionFeedback();
for(UsedQuestion uq : m_UsedQuestions.values())
{
Questions question = (Questions)session.getNamedQuery("questionById").setInteger("questionId", uq.getQuestionId()).uniqueResult();
Set<QuestionFeedback> questionFeedback = question.getQuestionFeedback();
QuestionFeedback qf = new QuestionFeedback(triviaGame, question, uq.getProvidedAnswer());
questionFeedback.add(qf);
gameFeedback.add(qf);
session.save(qf);
if(uq.isCorrect())
++correctQuestions;
}
triviaGame.setCorrectQuestions(correctQuestions);
tx.commit();
The code fails on the call to session.save(). The error I get is:
Code:
Error returned from server: not-null property references a null or transient value: QuestionFeedback._questionFeedbackBackref
Tracing through the code, I get this failure from the Nullability class, when it checks the class's fields -- the field that fails is the ID field, which, to me, implies that the ID generator isn't working. The database I'm using is MySQL 5.1, and the column in question is marked as auto_increment.
As I mentioned, this is the only class in my app that has this problem. Any advice as to where to start looking for a solution would be greatly appreciated.
Thanks in advance.
C