• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tree structure in Hibernate

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm learning hibernate and thought I'd do a simple task management application as a bit of study practice.

I have a class sort of like so:



A database table sort of like so:
id
parent_task_id
...other properties...

And lastly a xml mapping sort of like so:


Notice the collection association is with other rows in the same table instead of another table as in most of the parent-child examples I've seen. The idea is that a task can have many tasks as children, and so on.

So, when I load up my list of tasks, the parent/child relationships are perfect. I have a custom tag that renders them recursively with links to expand/collapse tasks. Good so far.

Then I try to edit a task and the trouble starts. If I update a task that has no children, all is good. The hibernate traces indicate a single update and the row really updates. If I try to update a task that has children, I can see in the hibernate log traces that hibernate is issuing something like:

update task set title=?, ... other properties ... where id=? (Looks good to me)

followed by:
update task set parent_task_id=null, id=null where parent_task_id=?

Not good. This fails because of course id and parent id are not-null in the schema. What I don't understand is why it would be attempting to update any record's parent_task_id or id. And further why it's just setting to literal null rather than an argument placeholder.

I guess my questions are... can someone give me a bit of an explanation of why this second update happens when there are associated children. Is there a way to avoid this problem with my current design? Is the design totally stupid and inefficient and should be scrapped anyway?

Thanks in advance for any help.

cheers,
-Bob
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic