Mykola M 13 Anos atrás Great article, thanks a lot for sharing this knowledge.One insignificant remark:> A fourth gotcha is that even if you don't specify a projection> (thus resulting in a default of selecting all columns and implied "give me the entity"),> casting directly to a List<T> won't work as it does in custom finders, > because you're getting back a List<Object>, not a List.> The quick and dirty solution is to either (a) use addAll on a List > and typecast (simulating what happens in a custom finder), > or (b) add each result to a List<T> (cleaner to read).Adding each result one by one is unnecessary overhead, as is creation as another List implementation instance (a quite small overhead, but still unnecessary).This can be easily avoided by using code like this:List<T> listOfT = (List<T>) (List) listOfObject; Por favor, autentique-se para votar. Responda como... Cancelar
Umer Sayeed 11 Anos atrás How to use dynamic query for (NOT EQUAL TO) in liferay..,Eg..,SELECT * FROM table where userid!='10'; Por favor, autentique-se para votar. Responda como... Cancelar Mykola M Umer Sayeed 11 Anos atrás Hi Umer SayeedIt's similar to equals condition described in article. See there is:Criterion criterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Here RestrictionsFactoryUtil creates "equal" condition on eq method call.Same way RestrictionsFactoryUtil method ne can be used:Criterion criterion = RestrictionsFactoryUtil.ne("primaryKey.userId", userId);This will create "not equals" condition.Regards,Mykola Makhin. Por favor, autentique-se para votar. Responda como... Cancelar Mykola M Mykola M 11 Anos atrás P.S. Note also that you can negate any condition using RestrictionFactoryUtil.not(Criterion criterion) method.I.e. same thing could be done this way (same result, just 2 lines of code instead of 1):Criterion eqCriterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Criterion notEqCriterion = RestrictionFactoryUtil.not(eqCriterion);P.P.S. I also recommend you to look up RestrictionsFactoryImpl class source code when you have questions like this - you'll see what the methods actually do, as this factory is essentially proxying calls to Hibernate's org.hibernate.criterion.Restrictions util (documentation on which you can fine on Hibernate site - in case you're not familiar with it already), and wraps hibernate Criterion into Liferay's wrapper Criterion (see CriterionImpl). Por favor, autentique-se para votar. Responda como... Cancelar le xi zhang Umer Sayeed 10 Anos atrás ne!!!!or not ??? Por favor, autentique-se para votar. Responda como... Cancelar
Mykola M Umer Sayeed 11 Anos atrás Hi Umer SayeedIt's similar to equals condition described in article. See there is:Criterion criterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Here RestrictionsFactoryUtil creates "equal" condition on eq method call.Same way RestrictionsFactoryUtil method ne can be used:Criterion criterion = RestrictionsFactoryUtil.ne("primaryKey.userId", userId);This will create "not equals" condition.Regards,Mykola Makhin. Por favor, autentique-se para votar. Responda como... Cancelar Mykola M Mykola M 11 Anos atrás P.S. Note also that you can negate any condition using RestrictionFactoryUtil.not(Criterion criterion) method.I.e. same thing could be done this way (same result, just 2 lines of code instead of 1):Criterion eqCriterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Criterion notEqCriterion = RestrictionFactoryUtil.not(eqCriterion);P.P.S. I also recommend you to look up RestrictionsFactoryImpl class source code when you have questions like this - you'll see what the methods actually do, as this factory is essentially proxying calls to Hibernate's org.hibernate.criterion.Restrictions util (documentation on which you can fine on Hibernate site - in case you're not familiar with it already), and wraps hibernate Criterion into Liferay's wrapper Criterion (see CriterionImpl). Por favor, autentique-se para votar. Responda como... Cancelar
Mykola M Mykola M 11 Anos atrás P.S. Note also that you can negate any condition using RestrictionFactoryUtil.not(Criterion criterion) method.I.e. same thing could be done this way (same result, just 2 lines of code instead of 1):Criterion eqCriterion = RestrictionsFactoryUtil.eq("primaryKey.userId", userId);Criterion notEqCriterion = RestrictionFactoryUtil.not(eqCriterion);P.P.S. I also recommend you to look up RestrictionsFactoryImpl class source code when you have questions like this - you'll see what the methods actually do, as this factory is essentially proxying calls to Hibernate's org.hibernate.criterion.Restrictions util (documentation on which you can fine on Hibernate site - in case you're not familiar with it already), and wraps hibernate Criterion into Liferay's wrapper Criterion (see CriterionImpl). Por favor, autentique-se para votar. Responda como... Cancelar
le xi zhang Umer Sayeed 10 Anos atrás ne!!!!or not ??? Por favor, autentique-se para votar. Responda como... Cancelar