Foren

Case insensitive SELECT DISTINCT with DynamicQuery

Dirk Ulrich, geändert vor 12 Jahren.

Case insensitive SELECT DISTINCT with DynamicQuery

Junior Member Beiträge: 42 Beitrittsdatum: 21.10.11 Neueste Beiträge
I wonder how I can implement a DynamicQuery to get all DISTINCT values of a database table column in a case insensitive manner?
For the time being I am using this approach (distinct but case sensitive):

	public List<string> getAllDistinctCatalogKeys() throws SystemException {
		DynamicQuery query = DynamicQueryFactoryUtil.forClass(CatalogEntryImpl.class);

//		Junction junction = RestrictionsFactoryUtil.conjunction()
//			      .add(RestrictionsFactoryUtil.ilike("catalogKey", ProjectionFactoryUtil.property("catalogKey")));
//			    query.add(junction);
		
		  query.setProjection(ProjectionFactoryUtil
		    .distinct(ProjectionFactoryUtil.property("catalogKey")));
		  //TODO How to implement case insensitive select (upper()/lower())?
		  query.addOrder(OrderFactoryUtil.asc("catalogKey"));
		  
		  @SuppressWarnings("unchecked")
		  List<string> keys = catalogEntryLocalService.dynamicQuery(query);
		  return keys;
	}</string></string>


But this approach gets two results for "fish" and "FISH". How can I modify this DynamicQuery to get the case insensitive result so that the query gets just one match (fish or FISH). I guess, there must be a way to use something like upper(...) or lower(...).