• 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:

return type of multi-object finder/select

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somewhere I read that the return type of the multi-object select method can be either Collection or Set, but the return type of the multi-entity finder method can only be Collection.

Can someone please confirm?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not necessary. It could be a Set both for Select/Finder methods. If you have DISTINCT keyword in your EJB-QL, the result is a Set!
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Balaji, what you say is interesting.

Do you mean that with DISTINCT used, the result type is actually a java.util.Set (not a Collection), or that it's "like a Set" because there is no duplicate values?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What i understand is that you can return java.util.Collection or java.util.Set from the finder methods

Correct me if i am wrong


Thanks,
Shrimon
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that's what I understood too, but I didn't read the spec deeply yet about this, and so I'd be happy to know.
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have skimmed through the spec and I think the spec only mentions about the two scenarios:
1. If the return type is Collection and DISTINCT is not specified ...
2. If the return type is Set and DISTINCT is not specified ...

I didn't come across a scenario in spec which says about "when DISTINCT is used and return type is Collection...".

I think in this scenario, we should get Collection ("set like") as the returned value. But, it *may* depend on container implementation.

Frederic, if you are going to implement Entity Bean code, can you also try this scenario in the bean code and then confirm what result do you see?
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
----------
page 233
If the EJB QL query is specified for a method whose return type is java.util.Collection , the
collection of values returned by the Container may contain duplicates if DISTINCT is not specified in
the SELECT clause. If the query is specified for a method whose result type is java.util.Set, but
does not specify DISTINCT, the container must interpret the query as if SELECT DISTINCT had been
specified.
------------
ofcourse if u have distinct in a collection type result... the result will be the same as that of set.

Frederic Esnault since u are watching this thread... is it necessry for the primary key class(compound key example on you site) to have the getters and setters in addition to the getters and setters in the bean class.
thanks
[ June 29, 2006: Message edited by: Srividhya Anand ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic