AvenashKrish / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

Return type of searchGeneric #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
currently, searchGeneric returns List and searchUniqueGeneric returns 
Object. This means it must be explicitly casted when used, for example:

//Note: this also causes a compiler warning for unsafe cast
List<User> = (List<User>) userDao.searchGeneric(search);

User user = (User) userDao.searchUniqueGeneric(search);

However, there is a language feature that will determine the return type at 
compile time based on context. This may save some trouble...

public <Q> List<Q> searchGeneric(Search search);
public <Q> Q searchUniqueGeneric(Search search);

This could simply be used as follows...

List<User> = userDao.searchGeneric(search);

User user = userDao.searchUniqueGeneric(search);

Original issue reported on code.google.com by dwolvert on 3 Aug 2009 at 12:02

GoogleCodeExporter commented 9 years ago

Original comment by dwolvert on 7 Aug 2009 at 12:17

GoogleCodeExporter commented 9 years ago
The actual resolution to this was to remove searchGeneric and 
searchUniqueGeneric 
altogether and change search() and searchUnique() to use the approach listed 
above.

I can see advantages to the old way of having search return a list or objects 
of the dao 
entity type, however the necessity of having a searchGeneric in addition to 
plain search 
was pretty confusing. So I think we're better off with this change.

Original comment by dwolvert on 12 Mar 2010 at 3:34