Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return type of multi-object finder/select

 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • 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?
 
Balaji VR
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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!
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • 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?
 
shri mon
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
Balaji Anand
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic