Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

List for 1:many

 
G Nguyen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to implement a 1:many bidirection association using a list,
something like

PARENT (
ID number primary key
)

CHILD (
ID number primary key,
PARENT_ID number, references PARENT,
CHILD_ORDER number
)

The hibernate mappings for both are set up, and I can cascade insert (parent mapping has list with cascade="all") the CHILD record by session.save() on the parent record. Question is, if there are multiple children, eg. order=0,1,2,3 and I would like to delete one, eg. CHILD_ORDER=2. List.remove(index) supports this functionality. But do I have to go back and reorder every child record with CHILD_ORDER > 2? Hibernate doesn't seem to do it automatically when I call session.save() on the parent object. If I leave a hole in the list, Hibernate still thinks there are 4 children (it does a select max(CHILD_ORDER)+1 to get the number of children.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic