jliu3008 / hibernate-generic-dao

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

Add a method to retrieve only the IDs #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Add a method to retrieve only the IDs. Something like :
List<ID> searchIDs(ISearch search)
and
SearchResult<ID> searchAndCount(ISearch search)

Original issue reported on code.google.com by cimballi...@gmail.com on 22 Sep 2010 at 7:05

GoogleCodeExporter commented 9 years ago
I do not believe such a method needs to be in the core framework. In my 
experience this convenience method is not often used in most projects. Since 
the DAOs are exstensible you can extend them to create your own base DAO that 
adds this method if you find it useful.

When the search object comes into your method, you can modify it to set fields 
to just "id". For example:

Search modifiedSearch = SearchUtil.shallowCopy(search);
modifiedSearch.setFields(Collections.singletonList(new Field("id")));

Original comment by dwolvert on 22 Sep 2010 at 9:57

GoogleCodeExporter commented 9 years ago
Yeah, you are right. In fact I forgot that you don't have the column name for 
the ID, only the type. And so it's not so interesting to have it in the core 
framework.

Original comment by cimballi...@gmail.com on 22 Sep 2010 at 10:16

GoogleCodeExporter commented 9 years ago
To make it even simpler, with Hibernate (and I believe JPA?), "id" will always 
refer to the id column no matter what the actual column name.

Original comment by dwolvert on 22 Sep 2010 at 10:28