• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

"Set" or "List" for storing foreign key objects

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using the classes that Hibernate-tools created for me.(i reverse engineered my database)
It seems like Hibernate stores the entries that are mapped to another one as a foreign key
in a Set(HashSet).And i am guessing that it would be better to have them stored in a List
or ArrayList since i will display those data in a table using JSF,and with Lists reaching the data
easier(using get(index)).(i dont know if i can send a Set into a datatable or not).

According to the situation,what do you advice me?Should i change Set variables to List's?
Would that make a problem?

Thank you for your answers..
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was doing JSF/Hibernate work, and found it more than annoying dealing with the fact that JSF components don't like Sets. I'm not sure why the h:dataTable couldn't just take a collection as an argument, and boht a Set and java.util.List would work? I'm sure there's a good reason, but it does make it difficult when you've got a set and need a List.

I grabbed this makeList class which is documented in this blog. It gets around the List/Set problem fairly nicely.

makeList JSF Code for Converting a Set to a List for a Custom Tag or <h:dataTable>

The way this guy maps the class to the managed bean, the h:dataTable looks something like this when it is fed a set:




Oracle has something as well.

Oracle MakeList Component

I found it just easier to return List objects to JSF as opposed to Sets. But then again, your view layer shouldn't impacting decisions in your model. But then again, this isn't a perfect world.

-Cameron McKenzie



 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well, on my point about not understanding why the h:dataTable can't take a simple Collection, here's a response:

One of the more personally surprising usability complaints I've heard was that the JSF UIData component does not support Sets. I hadn't anticipated that one. The underlying reason is that UIData is built around indexed data. For example, you can ask it to show rows 10,000 through 10,099. Such an operation would be nightmarishly expensive in a Set:



Adam Winer

-Cameron McKenzie
 
fatih soylemez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So ,i assume that using an iterator to migrate the data into a List
would be a more costly solution.I know this will sound silly but
can you give me a short explanation about how to utilize from
that ListFromCollection class since it has no method which
gets a Set as an argument and returns a List.

Thank you
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Faith, that code worked, and I could just pass it a set, and the dataList used it as a List.

I looked at that code a million times, looking for arguments passed in and constructors and what have you, and I couldn't 'freakin' figure out what the heck was going on. Seriously, it bugged me big time.

It could be Haitian Vodoo or Cosmic Energy or something of the like. I really have no idea. But the darn thing worked and got me out of a pickle. Maybe you can figure it out and explain it to me?



-Cameron McKenzie

 
fatih soylemez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
..I wish i could..As a noob,i used an iterator to save the data into a list,and sent this list
to a datagrid.



Now my problem is,i want to navigate to the movie page whose image is clicked.
But the choosen movie whose image is clicked,is an element of the list.
I can neither directly get the data of that object(Movie),nor take it from the list(i dont know its index) on the next page.
I need to send the clicked movie's id into a movieBean class method and retrieve the info of
that movie to use on the next page.Can anyone suggest me an idea ?

Thank you..



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic