Description of problem: When using the code below, I'm getting an Integrity Violation when trying to save the encapsulating class. The exception is thrown on the tx.commit() line.
Looking at the data actually stored into the database via the HSQL command line, I see the WorkingSet created, I see either none or 1 of the WorkingTasks created, but the set_id is 'null'. For some reason when doing the new WorkingTask() and save()ing it, the set_id column (though the column -is- there... so something's working), is not getting the value of the 'owning' WorkingSet'. I believe I'm setting up something wrong in the Set definition, but I'll be darned if I can figure out what it is.
My apologies for the size of the post and the dump here, but this is a somewhat critical-path issue right now, and I've STFW'ed, RTFM'ed, and every other acronym I can think of (including talking to a lot of people on IRC :)
Thanks for any help you can provide.
Hibernate version: 3.0
Mapping documents:
<class name="com.arete.JQuo.WorkingSet" table="workingsets">
<id name="id" column="set_id" type="long">
<generator class="increment"/>
</id>
<property name="owner" column="ws_name" type="string" />
<property name="comment" column="ws_note" type="string" />
<property name="checkedout" column="ws_added" type="timestamp" />
<set name="tasklist" cascade="all" >
<key column="set_id" not-null="true" />
<one-to-many class="com.arete.JQuo.WorkingTask"/>
</set>
</class>
and
<class name="com.arete.JQuo.WorkingTask" table="ws_tasks">
<id name="id" column="task_id" type="long">
<generator class="increment"/>
</id>
<property name="name" column="task_name" type="string" />
<property name="note" column="task_note" type="text" />
<property name="added" column="task_added" type="timestamp" />
(snip... this is a long class)
<property name="parenttask" column="task_parenttask" type="integer" />
</class>
Code between sessionFactory.openSession() and session.close():
Session session = myFactory.openSession();
tx = session.beginTransaction();
log.info("Creating the working set...");
mySet = new WorkingSet();
mySet.setowner(setUser);
session.save(mySet);
newId = mySet.getId();
log.info("ID of newly created working set is " + newId);
tx.commit();
tx = session.beginTransaction();
log.info("Fetching the Tasks...");
Query query = session.createQuery("from Task");
for (Iterator it = query.iterate(); it.hasNext();) {
task = (Task) it.next();
wTask = new WorkingTask();
wTask.setname(task.getname());
wTask.setnote(task.getnote());
log.info("wTask is " + wTask.toString());
log.info("wTask name is " + wTask.getname());
log.info("wTask note is " + wTask.getnote());
taskRows.add(wTask);
}
mySet.settasklist(taskRows);
session.saveOrUpdate(mySet);
tx.commit();
session.close();
Full stack trace of any exception that occurs:
11:00:07,650 INFO [STDOUT] Hibernate: insert into ws_tasks (task_name, task_note, task_added, task_reqorgid, task_reqwhoid, task_installid, task_licenseid, task_app, task_module, task_categories, task_folder, task_woid, task_sharepct, task_due, task_release, task_stat, task_ownwhoid, task_stepownid, task_stepitem, task_billrate, task_stepstat, task_comments, task_closed, task_parenttask, set_id, task_id) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
11:00:07,838 WARN [JDBCExceptionReporter] SQL Error: -177, SQLState: 23000
11:00:07,838 ERROR [JDBCExceptionReporter] Integrity constraint violation - no parent FKB5C5586B389BB6BD table: WORKINGSETS in statement [insert into ws_tasks (task_name, task_note, task_added, task_reqorgid, task_reqwhoid, task_installid, task_licenseid, task_app, task_module, task_categories, task_folder, task_woid, task_sharepct, task_due, task_release, task_stat, task_ownwhoid, task_stepownid, task_stepitem,task_billrate, task_stepstat, task_comments, task_closed, task_parenttask, set_id, task_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
11:00:07,839 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.arete.JQuo.WorkingTask]
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
Name and version of the database you are using: HSQL - er, whatever comes iwth JBoss 4.0.2.
The generated SQL (show_sql=true): In the trace above.
Debug level Hibernate log excerpt: This I do not have, though I think the dump above is complete enough.
_________________ ----
<a href="http://planet-geek.com/">Planet Geek!</a>
|