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

switch from set to list, many-to-many

 
Matt Horton
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As I get to know hibernate, it seems pretty sweet. However, I'm having trouble switching a hibernate mapped many-to-many relationship from a set to a list...

Consider the following foobar example; how would one modify the mappings in the page, e.g.



to use a list? I seem to be stuck on the element list-index; that is, I want to ask hibernate to use the order that the records come in as the basis for their list-index, but I'm not sure how to do so. That is, if a request returns records whose primary-keys are e.g. 13000, 5071, 9854, then the list-index for those elements would be 3,1,2... ordered to 1,2,3...

Do I have to use a real column for the list-index?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sort of yes. There is another way, but I have not used it. I think they talk about it in the help file.
 
Matt Horton
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lamont,

I couldn't find the material in the help file, so I went ahead and added the columns to the table. Works like a charm... thanks...

fwiw, if other ranchers find this during searches, check into the set order-by functionality. It also works well,,, I just decided to use an ordered list for weird, long user-session updates.
 
Matt Horton
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
egatz! I spoke to soon...

I seem to be able to persist the list-index for one side of the relationship, or if I reverse the inverse relationships, I can save the list-index for the other side of the relationship. Unfortunately, I can't do a bidirectional many-to-many AND persist the list-indexes (indices?) for both sides of the relationship.


[ March 12, 2007: Message edited by: Matt Horton ]
 
Matt Horton
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, for forum-dredgers of the future, I suggest that you read the following:
http://forums.hibernate.org/viewtopic.php?t=943384&highlight=bidirectional+listindex&sid=1e19f557855a43d8854db19a7f411d27

this link inspired me to take a somewhat dirty approach to taking care of the list-index issue (i was persistent, if not slow to actually read). That is, I used 2 uni-directional links with TWO JOIN TABLES. egatz! but, if you want order for both sides of the relationship, so be it. Hibernate will persist the list-index for you, if inverse is false for both sides of the relationship, and if you set not-null in the key column.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic